@rexeus/typeweaver-gen 0.0.3 β†’ 0.0.4

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/README.md CHANGED
@@ -1,267 +1,150 @@
1
- # @rexeus/typeweaver-gen
1
+ # 🧡✨ @rexeus/typeweaver-gen
2
2
 
3
- Code generation engine and utilities for TypeWeaver plugins.
3
+ [![npm version](https://img.shields.io/npm/v/@rexeus/typeweaver-gen.svg)](https://www.npmjs.com/package/@rexeus/typeweaver-gen)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
4
6
 
5
- ## Overview
7
+ Typeweaver is a type-safe HTTP API framework built for API-first development with a focus on
8
+ developer experience. Use typeweaver to specify your HTTP APIs in TypeScript and Zod, and generate
9
+ clients, validators, routers, and more ✨
6
10
 
7
- This package provides the plugin architecture and utilities that power TypeWeaver's extensible code
8
- generation system. It includes base classes, context utilities, and the plugin registry system.
11
+ ## πŸ“ Generation Package
9
12
 
10
- ## Installation
13
+ Provides the core components for generating code with typeweaver. This package forms the basis for
14
+ all plugins.
11
15
 
12
- ```bash
13
- npm install @rexeus/typeweaver-gen
14
- ```
16
+ ---
15
17
 
16
- **Peer Dependencies:**
18
+ ## πŸ“₯ Installation
17
19
 
18
20
  ```bash
19
- npm install @rexeus/typeweaver-core
20
- ```
21
-
22
- ## Plugin Architecture
23
-
24
- ### Creating a Plugin
25
-
26
- ```typescript
27
- import { BasePlugin, type GeneratorContext } from "@rexeus/typeweaver-gen";
28
-
29
- export default class MyPlugin extends BasePlugin {
30
- public name = "my-plugin";
31
-
32
- public override generate(context: GeneratorContext): Promise<void> | void {
33
- // Your generation logic here
34
- const content = context.renderTemplate(templatePath, templateData);
35
- context.writeFile("relative/path/to/output.ts", content);
36
- context.addGeneratedFile("relative/path/to/output.ts");
37
- }
38
- }
39
- ```
40
-
41
- ### Plugin Context
42
-
43
- The `GeneratorContext` provides utilities for code generation:
44
-
45
- ```typescript
46
- interface GeneratorContext {
47
- // Input/output directories
48
- outputDir: string;
49
- inputDir: string;
50
- templateDir: string;
51
- coreDir: string;
52
-
53
- // Resource data
54
- resources: GetResourcesResult;
55
-
56
- // Configuration
57
- config: PluginConfig;
58
-
59
- // Utility functions
60
- writeFile: (relativePath: string, content: string) => void;
61
- renderTemplate: (templatePath: string, data: unknown) => string;
62
- addGeneratedFile: (relativePath: string) => void;
63
- getGeneratedFiles: () => string[];
64
- }
65
- ```
66
-
67
- ### Utility Functions
68
-
69
- #### `writeFile(relativePath, content)`
70
-
71
- Writes files relative to the output directory with automatic directory creation:
72
-
73
- ```typescript
74
- context.writeFile("users/UserClient.ts", generatedClientCode);
75
- ```
76
-
77
- #### `renderTemplate(templatePath, data)`
78
-
79
- Renders EJS templates with provided data:
80
-
81
- ```typescript
82
- const content = context.renderTemplate(path.join(__dirname, "templates", "Client.ejs"), {
83
- entityName,
84
- operations,
85
- coreDir: context.coreDir,
86
- });
87
- ```
88
-
89
- #### `addGeneratedFile(relativePath)`
90
-
91
- Tracks generated files (automatically called by `writeFile`):
92
-
93
- ```typescript
94
- context.addGeneratedFile("users/UserClient.ts");
21
+ npm install -D @rexeus/typeweaver-gen
95
22
  ```
96
23
 
97
- ## Resource System
24
+ ## πŸ’‘ How to use
98
25
 
99
- The resource system provides structured access to API definitions:
26
+ Most users don’t depend on this package directly β€” use the CLI instead:
27
+ [`@rexeus/typeweaver`](https://github.com/rexeus/typeweaver/tree/main/packages/cli/README.md). If you’re writing a plugin, start here.
100
28
 
101
- ### Resource Types
29
+ ### πŸš€ Minimal plugin
102
30
 
103
- ```typescript
104
- interface GetResourcesResult {
105
- entityResources: Record<string, OperationResource[]>;
106
- sharedResponseResources: SharedResponseResource[];
107
- }
108
-
109
- interface OperationResource {
110
- entityName: string;
111
- definition: HttpOperationDefinition;
112
- outputDir: string;
113
- outputRequestFile: string;
114
- outputResponseFile: string;
115
- outputRequestValidationFile: string;
116
- outputResponseValidationFile: string;
117
- // ... more output file paths
118
- }
119
-
120
- interface SharedResponseResource {
121
- name: string;
122
- definition: HttpResponseDefinition;
123
- outputDir: string;
124
- outputFileName: string;
125
- outputFile: string;
126
- }
127
- ```
128
-
129
- ### Using Resources
31
+ ```ts
32
+ import { BasePlugin, type GeneratorContext } from "@rexeus/typeweaver-gen";
130
33
 
131
- ```typescript
132
34
  export default class MyPlugin extends BasePlugin {
133
- public name = "my-plugin";
134
-
135
- public override generate(context: GeneratorContext): void {
136
- // Iterate through entities
137
- for (const [entityName, operations] of Object.entries(context.resources.entityResources)) {
138
- // Generate entity-level code
139
- this.generateEntityCode(entityName, operations, context);
140
-
141
- // Generate operation-level code
142
- for (const operation of operations) {
143
- this.generateOperationCode(operation, context);
144
- }
145
- }
146
-
147
- // Use shared responses
148
- for (const sharedResponse of context.resources.sharedResponseResources) {
149
- this.generateSharedResponse(sharedResponse, context);
35
+ // Give your plugin a unique name
36
+ name = "my-plugin";
37
+
38
+ // Use the generate phase to render templates and write files
39
+ async generate(context: GeneratorContext) {
40
+ for (const [entity, { operations }] of Object.entries(context.resources.entityResources)) {
41
+ const content = context.renderTemplate("Entity.ejs", {
42
+ entity,
43
+ operations,
44
+ coreDir: context.coreDir,
45
+ });
46
+ context.writeFile(`${entity}/${entity}Stuff.ts`, content);
150
47
  }
151
48
  }
152
49
  }
153
50
  ```
154
51
 
155
- ## Template System
156
-
157
- ### Template Structure
158
-
159
- Templates should be placed in a `templates/` directory within your plugin:
52
+ Templates live under your plugin’s `src/templates`. They receive your data object as EJS locals.
160
53
 
161
- ```
162
- my-plugin/
163
- β”œβ”€β”€ src/
164
- β”‚ β”œβ”€β”€ index.ts
165
- β”‚ β”œβ”€β”€ MyGenerator.ts
166
- β”‚ └── templates/
167
- β”‚ β”œβ”€β”€ Client.ejs
168
- β”‚ └── Router.ejs
169
- └── package.json
170
- ```
54
+ ## πŸ”§ What it provides
171
55
 
172
- ### Template Usage
56
+ - Base classes: `BasePlugin`, `BaseTemplatePlugin` for lifecycle defaults, EJS helpers, and lib
57
+ copying.
58
+ - Types & contexts: `TypeweaverPlugin`, `PluginContext`, `GeneratorContext` with `writeFile`,
59
+ `renderTemplate`, and file tracking.
60
+ - Registry: `PluginRegistry` to register and query plugins; the CLI orchestrates lifecycle
61
+ execution.
62
+ - Resource model: `GetResourcesResult`, `EntityResources`, representing the normalized API data
63
+ derived from your definition.
173
64
 
174
- Templates receive context data and can use EJS syntax:
65
+ ## πŸ”Œ Plugin lifecycle
175
66
 
176
- ```ejs
177
- <%# templates/Client.ejs %>
178
- import { ApiClient } from "<%= coreDir %>";
67
+ The lifecycle keeps concerns separated and makes it easy to compose multiple plugins. Implement only
68
+ what you need.
179
69
 
180
- export class <%= pascalCaseEntityName %>Client extends ApiClient {
181
- <% for (const operation of operations) { %>
182
- public <%= operation.operationId %>() {
183
- // Generated method
184
- }
185
- <% } %>
186
- }
187
- ```
188
-
189
- ## Plugin Lifecycle
190
-
191
- ### Lifecycle Hooks
192
-
193
- ```typescript
194
- interface TypeWeaverPlugin {
195
- /**
196
- * Initialize the plugin
197
- * Called before any generation happens
198
- */
199
- initialize?(context: PluginContext): Promise<void> | void;
200
-
201
- /**
202
- * Collect and transform resources
203
- * Allows plugins to modify the resource collection
204
- */
70
+ ```ts
71
+ type TypeweaverPlugin = {
72
+ name: string;
73
+ initialize?(context: PluginContext): void | Promise<void>;
205
74
  collectResources?(
206
75
  resources: GetResourcesResult
207
- ): Promise<GetResourcesResult> | GetResourcesResult;
208
-
209
- /**
210
- * Main generation logic
211
- * Called with all resources and utilities
212
- */
213
- generate?(context: GeneratorContext): Promise<void> | void;
214
-
215
- /**
216
- * Finalize the plugin
217
- * Called after all generation is complete
218
- */
219
- finalize?(context: PluginContext): Promise<void> | void;
220
- }
76
+ ): GetResourcesResult | Promise<GetResourcesResult>;
77
+ generate?(context: GeneratorContext): void | Promise<void>;
78
+ finalize?(context: PluginContext): void | Promise<void>;
79
+ };
221
80
  ```
222
81
 
223
- ## Built-in Plugins
224
-
225
- TypeWeaver includes several built-in plugins:
82
+ - Initialize phase (`initialize`): Load and validate plugin configuration, check prerequisites.
83
+ - Collect Resources phase (`collectResources`): Inspect the normalized API model; derive or enrich
84
+ metadata (naming, groupings), filter or reorder resources, and share derived artifacts across
85
+ plugins if needed.
86
+ - Generate phase (`generate`): Render templates and emit code using `context.writeFile` (tracked);
87
+ copy or produce any runtime libraries required by the generated code.
88
+ - Finalize phase (`finalize`): Post-process outputs, clean stale generated files, and perform final
89
+ organization steps.
226
90
 
227
- - **@rexeus/typeweaver-types** - TypeScript types and Zod validators
228
- - **@rexeus/typeweaver-clients** - HTTP API clients
229
- - **@rexeus/typeweaver-aws-cdk** - AWS CDK constructs and HTTP API routers
91
+ ## 🧰 Generator context
230
92
 
231
- ## Best Practices
93
+ The `GeneratorContext` describes the generation phase: it provides access to resolved paths,
94
+ configuration, the normalized resources, and helper methods for safe file emission and templating.
95
+ You receive it only inside the `generate` lifecycle method.
232
96
 
233
- ### File Organization
97
+ ```ts
98
+ type GeneratorContext = {
99
+ inputDir: string;
100
+ outputDir: string;
101
+ templateDir: string;
102
+ coreDir: string;
103
+ config: PluginConfig;
104
+ resources: GetResourcesResult;
105
+ writeFile(rel: string, content: string): void; // mkdir -p + write + track
106
+ // Tracked files are automatically exported via a generated barrel index.ts
107
+ renderTemplate(tplPath: string, data: unknown): string; // EJS render
108
+ addGeneratedFile(rel: string): void; // track only
109
+ getGeneratedFiles(): string[]; // list tracked files
110
+ };
111
+ ```
234
112
 
235
- - Use consistent naming patterns for generated files
236
- - Organize output by entity or feature
237
- - Include proper imports and exports
113
+ ### πŸ“¦ Shipping runtime helpers
238
114
 
239
- ### Template Design
115
+ Sometimes your generated code needs small reusable runtime pieces (e.g., abstract classes, adapters,
116
+ validators, utils etc.). Ship them with your plugin and copy them into the consumer’s generated
117
+ output.
240
118
 
241
- - Keep templates focused and modular
242
- - Use consistent variable naming
243
- - Include proper TypeScript types in generated code
119
+ - Where to put them: Place TypeScript files under your plugin’s `src/lib`. They will compile to
120
+ `dist/lib` when you build the plugin.
121
+ - Copy them:
244
122
 
245
- ### Error Handling
123
+ ```ts
124
+ import path from "path";
125
+ import { fileURLToPath } from "url";
126
+ import { BasePlugin, type GeneratorContext } from "@rexeus/typeweaver-gen";
246
127
 
247
- - Validate input data before generation
248
- - Provide clear error messages
249
- - Handle edge cases gracefully
128
+ // Needed to resolve __dirname in ES modules
129
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
250
130
 
251
- ```typescript
252
- export default class MyPlugin extends BasePlugin {
253
- public name = "my-plugin";
131
+ export default class MyPlugin extends BasePlugin {
132
+ name = "my-plugin";
254
133
 
255
- public override generate(context: GeneratorContext): void {
256
- try {
257
- // Generation logic
258
- } catch (error) {
259
- throw new Error(`Plugin ${this.name} failed: ${error.message}`);
134
+ generate(context: GeneratorContext) {
135
+ const libSourceDir = path.join(__dirname, "lib");
136
+ this.copyLibFiles(context, libSourceDir, this.name); // -> <output>/lib/my-plugin
260
137
  }
261
138
  }
262
- }
263
- ```
139
+ ```
140
+
141
+ ## πŸ“Œ Notes
142
+
143
+ - Plugins are configured/executed by the CLI (`@rexeus/typeweaver`). See the CLI options
144
+ [here](https://github.com/rexeus/typeweaver/tree/main/packages/cli/README.md#️-options).
145
+ - Keep plugins focused: one concern per plugin (clients, routers, infra).
146
+ - Prefer `GeneratorContext.writeFile` over manual fs writes for tracking and directory setup.
264
147
 
265
- ## License
148
+ ## πŸ“„ License
266
149
 
267
- ISC Β© Dennis Wentzien 2025
150
+ Apache 2.0 Β© Dennis Wentzien 2025
package/dist/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2025 Dennis Wentzien
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/dist/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Copyright 2025 Dennis Wentzien
2
+
3
+ This project is licensed under the Apache License, Version 2.0
4
+ See LICENSE file for details.
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ type GetResourcesResult = {
6
6
  };
7
7
  type ExtendedResponseDefinition = IHttpResponseDefinition & {
8
8
  statusCodeName: string;
9
+ isReference: boolean;
9
10
  };
10
11
  type EntityName = string;
11
12
  type OperationResource = {
@@ -28,9 +29,11 @@ type OperationResource = {
28
29
  outputClientFile: string;
29
30
  outputClientFileName: string;
30
31
  };
31
- type EntityResources = Record<EntityName, OperationResource[]>;
32
+ type EntityResources = Record<EntityName, {
33
+ operations: OperationResource[];
34
+ responses: EntityResponseResource[];
35
+ }>;
32
36
  type SharedResponseResource = IHttpResponseDefinition & {
33
- isShared: true;
34
37
  sourceDir: string;
35
38
  sourceFile: string;
36
39
  sourceFileName: string;
@@ -38,23 +41,32 @@ type SharedResponseResource = IHttpResponseDefinition & {
38
41
  outputFileName: string;
39
42
  outputDir: string;
40
43
  };
44
+ type EntityResponseResource = IHttpResponseDefinition & {
45
+ sourceDir: string;
46
+ sourceFile: string;
47
+ sourceFileName: string;
48
+ outputFile: string;
49
+ outputFileName: string;
50
+ outputDir: string;
51
+ entityName: EntityName;
52
+ };
41
53
 
42
54
  /**
43
- * Configuration for a TypeWeaver plugin
55
+ * Configuration for a typeweaver plugin
44
56
  */
45
57
  type PluginConfig = Record<string, unknown>;
46
58
  /**
47
59
  * Context provided to plugins during initialization and finalization
48
60
  */
49
- interface PluginContext {
61
+ type PluginContext = {
50
62
  outputDir: string;
51
63
  inputDir: string;
52
64
  config: PluginConfig;
53
- }
65
+ };
54
66
  /**
55
67
  * Context provided to plugins during generation
56
68
  */
57
- interface GeneratorContext extends PluginContext {
69
+ type GeneratorContext = PluginContext & {
58
70
  resources: GetResourcesResult;
59
71
  templateDir: string;
60
72
  coreDir: string;
@@ -62,17 +74,17 @@ interface GeneratorContext extends PluginContext {
62
74
  renderTemplate: (templatePath: string, data: unknown) => string;
63
75
  addGeneratedFile: (relativePath: string) => void;
64
76
  getGeneratedFiles: () => string[];
65
- }
77
+ };
66
78
  /**
67
79
  * Plugin metadata
68
80
  */
69
- interface PluginMetadata {
81
+ type PluginMetadata = {
70
82
  name: string;
71
- }
83
+ };
72
84
  /**
73
- * TypeWeaver plugin interface
85
+ * typeweaver plugin interface
74
86
  */
75
- interface TypeWeaverPlugin extends PluginMetadata {
87
+ type TypeweaverPlugin = PluginMetadata & {
76
88
  /**
77
89
  * Initialize the plugin
78
90
  * Called before any generation happens
@@ -93,35 +105,36 @@ interface TypeWeaverPlugin extends PluginMetadata {
93
105
  * Called after all generation is complete
94
106
  */
95
107
  finalize?(context: PluginContext): Promise<void> | void;
96
- }
108
+ };
97
109
  /**
98
110
  * Plugin constructor type
99
111
  */
100
- type PluginConstructor = new (config?: PluginConfig) => TypeWeaverPlugin;
112
+ type PluginConstructor = new (config?: PluginConfig) => TypeweaverPlugin;
101
113
  /**
102
114
  * Plugin module export
103
115
  */
104
- interface PluginModule {
116
+ type PluginModule = {
105
117
  default: PluginConstructor;
106
- }
118
+ };
107
119
  /**
108
120
  * Plugin registration entry
109
121
  */
110
- interface PluginRegistration {
122
+ type PluginRegistration = {
111
123
  name: string;
112
- plugin: TypeWeaverPlugin;
124
+ plugin: TypeweaverPlugin;
113
125
  config?: PluginConfig;
114
- }
126
+ };
115
127
  /**
116
- * TypeWeaver configuration
128
+ * typeweaver configuration
117
129
  */
118
- interface TypeWeaverConfig {
130
+ type TypeweaverConfig = {
119
131
  input: string;
120
132
  output: string;
121
- plugins?: Array<string | [string, PluginConfig]>;
133
+ shared?: string;
134
+ plugins?: (string | [string, PluginConfig])[];
122
135
  prettier?: boolean;
123
136
  clean?: boolean;
124
- }
137
+ };
125
138
  /**
126
139
  * Plugin loading error
127
140
  */
@@ -139,10 +152,10 @@ declare class PluginDependencyError extends Error {
139
152
  }
140
153
 
141
154
  /**
142
- * Base class for TypeWeaver plugins
155
+ * Base class for typeweaver plugins
143
156
  * Provides default implementations and common utilities
144
157
  */
145
- declare abstract class BasePlugin implements TypeWeaverPlugin {
158
+ declare abstract class BasePlugin implements TypeweaverPlugin {
146
159
  abstract name: string;
147
160
  description?: string;
148
161
  author?: string;
@@ -195,7 +208,7 @@ declare abstract class BaseTemplatePlugin extends BasePlugin {
195
208
  }
196
209
 
197
210
  /**
198
- * Registry for managing TypeWeaver plugins
211
+ * Registry for managing typeweaver plugins
199
212
  */
200
213
  declare class PluginRegistry {
201
214
  private plugins;
@@ -203,7 +216,7 @@ declare class PluginRegistry {
203
216
  /**
204
217
  * Register a plugin
205
218
  */
206
- register(plugin: TypeWeaverPlugin, config?: unknown): void;
219
+ register(plugin: TypeweaverPlugin, config?: unknown): void;
207
220
  /**
208
221
  * Get a registered plugin
209
222
  */
@@ -260,4 +273,5 @@ declare class Path {
260
273
  static relative(from: string, to: string): string;
261
274
  }
262
275
 
263
- export { BasePlugin, BaseTemplatePlugin, type EntityName, type EntityResources, type ExtendedResponseDefinition, type GeneratorContext, type GetResourcesResult, type OperationResource, Path, type PluginConfig, type PluginConstructor, type PluginContext, PluginContextBuilder, PluginDependencyError, PluginLoadError, type PluginMetadata, type PluginModule, type PluginRegistration, PluginRegistry, type SharedResponseResource, type TypeWeaverConfig, type TypeWeaverPlugin };
276
+ export { BasePlugin, BaseTemplatePlugin, Path, PluginContextBuilder, PluginDependencyError, PluginLoadError, PluginRegistry };
277
+ export type { EntityName, EntityResources, EntityResponseResource, ExtendedResponseDefinition, GeneratorContext, GetResourcesResult, OperationResource, PluginConfig, PluginConstructor, PluginContext, PluginMetadata, PluginModule, PluginRegistration, SharedResponseResource, TypeweaverConfig, TypeweaverPlugin };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import path from 'path';
2
1
  import fs from 'fs';
3
- import ejs from 'ejs';
2
+ import path from 'path';
3
+ import { render } from 'ejs';
4
4
 
5
5
  class PluginLoadError extends Error {
6
6
  constructor(pluginName, message) {
@@ -69,7 +69,7 @@ class BaseTemplatePlugin extends BasePlugin {
69
69
  */
70
70
  renderTemplate(templatePath, data) {
71
71
  const template = fs.readFileSync(templatePath, "utf8");
72
- return ejs.render(template, data);
72
+ return render(template, data);
73
73
  }
74
74
  /**
75
75
  * Write a file relative to the output directory
@@ -175,7 +175,7 @@ class PluginContextBuilder {
175
175
  renderTemplate: (templatePath, data) => {
176
176
  const fullTemplatePath = path.isAbsolute(templatePath) ? templatePath : path.join(params.templateDir, templatePath);
177
177
  const template = fs.readFileSync(fullTemplatePath, "utf8");
178
- return ejs.render(template, data);
178
+ return render(template, data);
179
179
  },
180
180
  addGeneratedFile: (relativePath) => {
181
181
  this.generatedFiles.add(relativePath);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rexeus/typeweaver-gen",
3
- "version": "0.0.3",
4
- "description": "Code generation engine and utilities for TypeWeaver plugins",
3
+ "version": "0.0.4",
4
+ "description": "Code generation engine and utilities for typeweaver plugins",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -14,7 +14,9 @@
14
14
  "files": [
15
15
  "dist",
16
16
  "package.json",
17
- "README.md"
17
+ "README.md",
18
+ "LICENSE",
19
+ "NOTICE"
18
20
  ],
19
21
  "keywords": [
20
22
  "api",
@@ -26,7 +28,7 @@
26
28
  "typeweaver"
27
29
  ],
28
30
  "author": "Dennis Wentzien <dw@rexeus.com>",
29
- "license": "ISC",
31
+ "license": "Apache-2.0",
30
32
  "repository": {
31
33
  "type": "git",
32
34
  "url": "git+https://github.com/rexeus/typeweaver.git",
@@ -37,10 +39,10 @@
37
39
  },
38
40
  "homepage": "https://github.com/rexeus/typeweaver#readme",
39
41
  "peerDependencies": {
40
- "@rexeus/typeweaver-core": "^0.0.3"
42
+ "@rexeus/typeweaver-core": "^0.0.4"
41
43
  },
42
44
  "devDependencies": {
43
- "@rexeus/typeweaver-core": "^0.0.3"
45
+ "@rexeus/typeweaver-core": "^0.0.4"
44
46
  },
45
47
  "dependencies": {
46
48
  "ejs": "^3.1.10"
@@ -48,7 +50,7 @@
48
50
  "scripts": {
49
51
  "typecheck": "tsc --noEmit",
50
52
  "format": "prettier --write .",
51
- "build": "pkgroll --clean-dist",
53
+ "build": "pkgroll --clean-dist && cp ../../LICENSE ../../NOTICE ./dist/",
52
54
  "preversion": "npm run build"
53
55
  }
54
56
  }