@nemmtor/ts-databuilders 0.0.1-alpha.2 → 0.0.1-alpha.21
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 +485 -10
- package/dist/main.js +7 -4
- package/package.json +48 -24
package/README.md
CHANGED
|
@@ -1,14 +1,489 @@
|
|
|
1
1
|
# 🧱 TS DataBuilders
|
|
2
|
-
|
|
3
|
-
Just add a @DataBuilder JSDoc tag, run one command, and get a fully-typed builder ready to use in your tests or factories.
|
|
2
|
+
Automatically generate type-safe builder classes from your TypeScript types to write cleaner, more focused tests.
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
## Installation
|
|
5
|
+
Install the package:
|
|
6
|
+
```bash
|
|
7
|
+
# npm
|
|
8
|
+
npm install -D @nemmtor/ts-databuilders
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
# pnpm
|
|
11
|
+
pnpm add -D @nemmtor/ts-databuilders
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
# yarn
|
|
14
|
+
yarn add -D @nemmtor/ts-databuilders
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
Configuration is optional - it fallbacks to sensible defaults.
|
|
19
|
+
|
|
20
|
+
### Configure via CLI flags (optional):
|
|
21
|
+
```bash
|
|
22
|
+
pnpm ts-databuilders --include "src/**/*.ts{,x}" --output-dir src/__generated__ --jsdoc-tag DataBuilder
|
|
23
|
+
```
|
|
24
|
+
You can also provide configuration by going through interactive wizard:
|
|
25
|
+
```bash
|
|
26
|
+
pnpm ts-databuilders --wizard
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Configure via config file (optional)
|
|
30
|
+
Ts-databuilders will try to find config file `ts-databuilders.json` in the root of your repository.
|
|
31
|
+
Config file is optional.
|
|
32
|
+
|
|
33
|
+
Example of default config file:
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"$schema": "https://raw.githubusercontent.com/nemmtor/ts-databuilders/refs/heads/main/schema.json",
|
|
37
|
+
"jsdocTag": "DataBuilder",
|
|
38
|
+
"inlineDefaultJsdocTag": "DataBuilderDefault",
|
|
39
|
+
"withNestedBuilders": true,
|
|
40
|
+
"outputDir": "generated/builders",
|
|
41
|
+
"include": "src/**/*.ts{,x}",
|
|
42
|
+
"fileSuffix": ".builder",
|
|
43
|
+
"fileCase": "kebab",
|
|
44
|
+
"builderSuffix": "Builder",
|
|
45
|
+
"defaults": {
|
|
46
|
+
"string": "",
|
|
47
|
+
"number": 0,
|
|
48
|
+
"boolean": false
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can generate a default configuration file by running `init` command:
|
|
54
|
+
```bash
|
|
55
|
+
pnpm ts-databuilders init
|
|
56
|
+
```
|
|
57
|
+
You can also generate it by providing values step by step in an interactive wizard:
|
|
58
|
+
```bash
|
|
59
|
+
pnpm ts-databuilders init --wizard
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Options Reference
|
|
64
|
+
|
|
65
|
+
| Name (in config file) | Flag (cli flags) | Description | Default |
|
|
66
|
+
|---------------|-------------------------------------------------------|-----------------------------------------|----------------------|
|
|
67
|
+
| jsdocTag | `--jsdoc-tag` | JSDoc tag to mark types for generation | `DataBuilder` |
|
|
68
|
+
| inlineDefaultJsdocTag | `--inline-default-jsdoc-tag` | JSDoc tag used to set default value of given field | `DataBuilderDefault` |
|
|
69
|
+
| withNestedBuilders | `--with-nested-builders` | When set to true ts-databuilders will use nested builders approach | `true` |
|
|
70
|
+
| outputDir | `--output-dir -o` | Output directory for generated builders | `generated/builders` |
|
|
71
|
+
| include | `--include -i` | Glob pattern for source files | `src/**/*.ts{,x}` |
|
|
72
|
+
| fileSuffix | `--file-suffix` | File suffix for builder files | `.builder` |
|
|
73
|
+
| fileCase | `--file-case` | Naming convention for generated builder file, one of 3: `kebab`, `camel`, `pascal` | `kebab` |
|
|
74
|
+
| builderSuffix | `--builder-suffix` | Class name suffix | `Builder` |
|
|
75
|
+
| defaults | `--default-string --default-number --default-boolean` | Default values for primitives | See example above |
|
|
76
|
+
|
|
77
|
+
**Priority:** CLI flags > Config file > Built-in defaults
|
|
78
|
+
|
|
79
|
+
#### Debugging
|
|
80
|
+
In order to turn on debug logs pass a flag: `--log-level debug`.
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
**1. Annotate your types with JSDoc:**
|
|
84
|
+
```ts
|
|
85
|
+
/**
|
|
86
|
+
* @DataBuilder
|
|
87
|
+
*/
|
|
88
|
+
type User = {
|
|
89
|
+
id: string;
|
|
90
|
+
email: string;
|
|
91
|
+
name: string;
|
|
92
|
+
isActive: boolean;
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
**2. Generate builders:**
|
|
96
|
+
```bash
|
|
97
|
+
pnpm ts-databuilders
|
|
98
|
+
```
|
|
99
|
+
For the `User` type above, you'll get:
|
|
100
|
+
```ts
|
|
101
|
+
import type { User } from "...";
|
|
102
|
+
import { DataBuilder } from "./data-builder";
|
|
103
|
+
|
|
104
|
+
export class UserBuilder extends DataBuilder<User> {
|
|
105
|
+
constructor() {
|
|
106
|
+
super({
|
|
107
|
+
id: "",
|
|
108
|
+
email: "",
|
|
109
|
+
name: "",
|
|
110
|
+
isActive: false
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
withId(id: User['id']) {
|
|
115
|
+
return this.with({ id });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
withEmail(email: User['email']) {
|
|
119
|
+
return this.with({ email });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
withName(name: User['name']) {
|
|
123
|
+
return this.with({ name });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
withIsActive(isActive: User['isActive']) {
|
|
127
|
+
return this.with({ isActive });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**3. Use in your tests:**
|
|
133
|
+
```ts
|
|
134
|
+
import { UserBuilder } from '...';
|
|
135
|
+
|
|
136
|
+
const testUser = new UserBuilder()
|
|
137
|
+
.withEmail('test@example.com')
|
|
138
|
+
.withIsActive(false)
|
|
139
|
+
.build();
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Why?
|
|
143
|
+
Tests often become cluttered with boilerplate when you need to create complex objects just to test one specific field. DataBuilders let you focus on what matters:
|
|
144
|
+
Imagine testing a case where document aggregate should emit an event when it successfully update it's content:
|
|
145
|
+
```ts
|
|
146
|
+
it('should emit a ContentUpdatedEvent', () => {
|
|
147
|
+
const aggregate = DocumentAggregate.create({
|
|
148
|
+
id: '1',
|
|
149
|
+
createdAt: new Date(),
|
|
150
|
+
updatedAt: new Date(),
|
|
151
|
+
content: 'old-content'
|
|
152
|
+
});
|
|
153
|
+
const userId = '1';
|
|
154
|
+
|
|
155
|
+
aggregate.updateContent({ updatedBy: userId, content: 'new-content' });
|
|
156
|
+
|
|
157
|
+
expect(...);
|
|
158
|
+
})
|
|
159
|
+
```
|
|
160
|
+
Above code is obfuscated with all of the default values you need to provide in order to satisfy typescript.
|
|
161
|
+
Where in reality the only thing specific to this single test is the fact that some new content was provided to `updateContent` method.
|
|
162
|
+
|
|
163
|
+
Imagine even more complex scenario:
|
|
164
|
+
```tsx
|
|
165
|
+
it('should show validation error when email is invalid', async () => {
|
|
166
|
+
render(<ProfileForm defaultValues={{
|
|
167
|
+
firstName: '',
|
|
168
|
+
lastName: '',
|
|
169
|
+
age: 0,
|
|
170
|
+
socials: {
|
|
171
|
+
linkedin: '',
|
|
172
|
+
github: '',
|
|
173
|
+
website: '',
|
|
174
|
+
twitter: '',
|
|
175
|
+
},
|
|
176
|
+
address: {
|
|
177
|
+
street: '',
|
|
178
|
+
city: '',
|
|
179
|
+
state: '',
|
|
180
|
+
zip: '',
|
|
181
|
+
},
|
|
182
|
+
skills: [],
|
|
183
|
+
bio: '',
|
|
184
|
+
email: 'invalid-email'
|
|
185
|
+
}}
|
|
186
|
+
/>)
|
|
187
|
+
|
|
188
|
+
await submitForm();
|
|
189
|
+
|
|
190
|
+
expect(...);
|
|
191
|
+
})
|
|
192
|
+
```
|
|
193
|
+
Again - in reality you should only be worried about email, not about whole form data.
|
|
194
|
+
|
|
195
|
+
Here's how above tests could be written with databuilders:
|
|
196
|
+
```ts
|
|
197
|
+
it('should emit a ContentUpdatedEvent', () => {
|
|
198
|
+
const aggregate = DocumentAggregate.create(
|
|
199
|
+
new CreateDocumentAggregatedPayloadBuilder().build()
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
aggregate.updateContent(
|
|
203
|
+
new UpdateDocumentContentPayloadBuilder().withContent('new-content').build()
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
expect(...);
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```tsx
|
|
211
|
+
it('should show validation error when email is invalid', async () => {
|
|
212
|
+
render(<ProfileForm defaultValues={
|
|
213
|
+
new ProfileFormInputBuilder.withEmail('invalid-email').build()} />
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
await submitForm();
|
|
217
|
+
|
|
218
|
+
expect(...);
|
|
219
|
+
})
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
This not only makes the test code less verbose but also highlights what is really being tested.
|
|
223
|
+
|
|
224
|
+
**Why not use AI for that?** While AI can generate test data, ts-databuilders is fast, free and deterministic.
|
|
225
|
+
|
|
226
|
+
[Read more about data builders.](http://www.natpryce.com/articles/000714.html)
|
|
227
|
+
|
|
228
|
+
## Nested Builders
|
|
229
|
+
> [!NOTE]
|
|
230
|
+
> Nested builders can be turned off by using withNestedBuilders option. Check configuration section for more details.
|
|
231
|
+
|
|
232
|
+
When your types contain complex nested objects, you can annotate their type definitions and TS DataBuilders will automatically generate nested builders, allowing you to compose them fluently.
|
|
233
|
+
### Example
|
|
234
|
+
|
|
235
|
+
**Input types:**
|
|
236
|
+
```ts
|
|
237
|
+
/**
|
|
238
|
+
* @DataBuilder
|
|
239
|
+
*/
|
|
240
|
+
export type User = {
|
|
241
|
+
name: string;
|
|
242
|
+
address: Address;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @DataBuilder
|
|
247
|
+
*/
|
|
248
|
+
export type Address = {
|
|
249
|
+
street: string;
|
|
250
|
+
city: string;
|
|
251
|
+
country: string;
|
|
252
|
+
};
|
|
253
|
+
```
|
|
254
|
+
**Generated builders:**
|
|
255
|
+
```ts
|
|
256
|
+
export class UserBuilder extends DataBuilder<User> {
|
|
257
|
+
constructor() {
|
|
258
|
+
super({
|
|
259
|
+
name: "",
|
|
260
|
+
address: new AddressBuilder().build();
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
withName(name: User['name']) {
|
|
265
|
+
return this.with({ name });
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
withAddress(address: DataBuilder<User['address']>) {
|
|
269
|
+
return this.with({ address: address.build() });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export class AddressBuilder extends DataBuilder<Address> {
|
|
274
|
+
constructor() {
|
|
275
|
+
super({
|
|
276
|
+
street: "",
|
|
277
|
+
city: "",
|
|
278
|
+
country: ""
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
withStreet(street: Address['street']) {
|
|
283
|
+
return this.with({ street });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
withCity(city: Address['city']) {
|
|
287
|
+
return this.with({ city });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
withCountry(country: Address['country']) {
|
|
291
|
+
return this.with({ country });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
**Usage:**
|
|
296
|
+
```ts
|
|
297
|
+
// ✅ Compose builders fluently
|
|
298
|
+
const user = new UserBuilder()
|
|
299
|
+
.withName('John Doe')
|
|
300
|
+
.withAddress(
|
|
301
|
+
new AddressBuilder()
|
|
302
|
+
.withStreet('123 Main St')
|
|
303
|
+
.withCity('New York')
|
|
304
|
+
)
|
|
305
|
+
.build();
|
|
306
|
+
// {..., address: { street: "123 Main st", city: "New York", country: "" } }
|
|
307
|
+
|
|
308
|
+
// ✅ Use default values
|
|
309
|
+
const userWithDefaultAddress = new UserBuilder().build();
|
|
310
|
+
// {..., address: { street: "", city: "", country: "" } }
|
|
311
|
+
|
|
312
|
+
// ✅ Override just one nested field
|
|
313
|
+
const userWithCity = new UserBuilder()
|
|
314
|
+
.withAddress(
|
|
315
|
+
new AddressBuilder()
|
|
316
|
+
.withCity('San Francisco')
|
|
317
|
+
)
|
|
318
|
+
.build();
|
|
319
|
+
// {..., address: { street: "", city: "San Francisco", country: "" } }
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Inline Default Values
|
|
323
|
+
> [!NOTE]
|
|
324
|
+
> It's your responsibility to provide inline default value that satisfies expected type.
|
|
325
|
+
|
|
326
|
+
While global defaults work well for most cases, sometimes you need field-specific default values. This is especially important for specialized string types like ISO dates, UUIDs etc.
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
/** @DataBuilder */
|
|
330
|
+
type Order = {
|
|
331
|
+
id: string; // Empty string - won't work as UUID
|
|
332
|
+
createdAt: string; // Empty string - Invalid Date!
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Generated:
|
|
336
|
+
constructor() {
|
|
337
|
+
super({
|
|
338
|
+
id: "",
|
|
339
|
+
createdAt: "", // new Date("") = Invalid Date
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Use `@DataBuilderDefault` JSDoc tag to override defaults per field:
|
|
345
|
+
```typescript
|
|
346
|
+
/** @DataBuilder */
|
|
347
|
+
type Order = {
|
|
348
|
+
/** @DataBuilderDefault '550e8400-e29b-41d4-a716-446655440000' */
|
|
349
|
+
id: string;
|
|
350
|
+
|
|
351
|
+
/** @DataBuilderDefault '2025-11-05T15:32:58.727Z' */
|
|
352
|
+
createdAt: string;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Generated:
|
|
356
|
+
constructor() {
|
|
357
|
+
super({
|
|
358
|
+
id: '550e8400-e29b-41d4-a716-446655440000',
|
|
359
|
+
createdAt: '2025-11-05T15:32:58.727Z',
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Supported Types
|
|
365
|
+
|
|
366
|
+
The library supports a wide range of TypeScript type features:
|
|
367
|
+
|
|
368
|
+
✅ **Primitives & Built-ins**
|
|
369
|
+
- `string`, `number`, `boolean`, `Date`
|
|
370
|
+
- Literal types: `'active' | 'inactive'`, `1 | 2 | 3`
|
|
371
|
+
|
|
372
|
+
✅ **Complex Structures**
|
|
373
|
+
- Objects and nested objects
|
|
374
|
+
- Arrays: `string[]`, `Array<number>`
|
|
375
|
+
- Tuples: `[string, number]`
|
|
376
|
+
- Records: `Record<string, string>` `Record<'foo' | 'bar', string>`
|
|
377
|
+
|
|
378
|
+
✅ **Type Operations**
|
|
379
|
+
- Unions: `string | number | true | false`
|
|
380
|
+
- Intersections: `A & B`
|
|
381
|
+
- Utility types: `Pick<T, K>`, `Omit<T, K>`, `Partial<T>`, `Required<T>`, `Readonly<T>`, `Extract<T, U>`, `NonNullable<T>`
|
|
382
|
+
- Branded types: `type UserId = string & { __brand: 'UserId' }`
|
|
383
|
+
|
|
384
|
+
✅ **References**
|
|
385
|
+
- Type references from the same file
|
|
386
|
+
- Type references from other files
|
|
387
|
+
- External library types (e.g., `z.infer<typeof schema>`)
|
|
388
|
+
|
|
389
|
+
**For a comprehensive example** of supported types, check out the [example-data/bar.ts](https://github.com/nemmtor/ts-databuilders/blob/main/example-data/bar.ts) file in the repository. This file is used during development and demonstrates complex real-world type scenarios.
|
|
390
|
+
|
|
391
|
+
## Important Rules & Limitations
|
|
392
|
+
|
|
393
|
+
### Unique Builder Names
|
|
394
|
+
Each type annotated with the JSDoc tag must have a **unique name** across your codebase:
|
|
395
|
+
```ts
|
|
396
|
+
// ❌ Error: Duplicate builder names
|
|
397
|
+
// In file-a.ts
|
|
398
|
+
/** @DataBuilder */
|
|
399
|
+
export type User = { name: string };
|
|
400
|
+
|
|
401
|
+
// In file-b.ts
|
|
402
|
+
/** @DataBuilder */
|
|
403
|
+
export type User = { email: string }; // 💥 Duplicate!
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Exported Types Only
|
|
407
|
+
Types must be **exported** to generate builders:
|
|
408
|
+
```ts
|
|
409
|
+
// ❌ Won't work
|
|
410
|
+
/** @DataBuilder */
|
|
411
|
+
type User = { name: string };
|
|
412
|
+
|
|
413
|
+
// ✅ Works
|
|
414
|
+
/** @DataBuilder */
|
|
415
|
+
export type User = { name: string };
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Type Aliases Only
|
|
419
|
+
Currently, only **type aliases** are supported as root builder types. Interfaces, classes etc. are not supported:
|
|
420
|
+
```ts
|
|
421
|
+
// ❌ Not supported
|
|
422
|
+
/** @DataBuilder */
|
|
423
|
+
export interface User {
|
|
424
|
+
name: string;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// ❌ Not supported
|
|
428
|
+
/** @DataBuilder */
|
|
429
|
+
export class User {
|
|
430
|
+
name: string;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// ✅ Supported
|
|
434
|
+
/** @DataBuilder */
|
|
435
|
+
export type User = {
|
|
436
|
+
name: string;
|
|
437
|
+
};
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Unsupported TypeScript Features
|
|
441
|
+
|
|
442
|
+
Some TypeScript features are not yet supported and will cause generation errors:
|
|
443
|
+
|
|
444
|
+
- **Recursive types**: Types that reference themselves
|
|
445
|
+
```ts
|
|
446
|
+
// ❌ Not supported
|
|
447
|
+
type TreeNode = {
|
|
448
|
+
value: string;
|
|
449
|
+
children: TreeNode[]; // Self-reference
|
|
450
|
+
};
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
- **Function types**: Properties that are functions
|
|
454
|
+
```ts
|
|
455
|
+
// ❌ Not supported
|
|
456
|
+
type WithCallback = {
|
|
457
|
+
onSave: (data: string) => void;
|
|
458
|
+
};
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
- typeof, keyof, unknown
|
|
462
|
+
|
|
463
|
+
### Alpha Stage
|
|
464
|
+
⚠️ **This library is in active development**
|
|
465
|
+
|
|
466
|
+
- Breaking changes may occur
|
|
467
|
+
- Not all edge cases are covered yet
|
|
468
|
+
- Test thoroughly before using in production
|
|
469
|
+
|
|
470
|
+
**Found an issue?** Please [report it on GitHub](https://github.com/nemmtor/ts-databuilders/issues) with:
|
|
471
|
+
- A minimal reproducible example (if possible)
|
|
472
|
+
- The type definition causing the issue
|
|
473
|
+
- The error message received
|
|
474
|
+
- Your `ts-databuilders.json` config and any provided CLI flags (if applicable)
|
|
475
|
+
|
|
476
|
+
You can also turn on debug logs by passing `--log-level debug` flag.
|
|
477
|
+
|
|
478
|
+
Your feedback helps improve the library for everyone! 🙏
|
|
479
|
+
|
|
480
|
+
## Similar Projects
|
|
481
|
+
- [effect-builder](https://github.com/slashlifeai/effect-builder) - a runtime library for building objects with Effect Schema validation.
|
|
482
|
+
|
|
483
|
+
## Contributing
|
|
484
|
+
|
|
485
|
+
Contributions welcome! Please open an issue or PR on [GitHub](https://github.com/nemmtor/ts-databuilders).
|
|
486
|
+
|
|
487
|
+
## License
|
|
488
|
+
|
|
489
|
+
MIT © [nemmtor](https://github.com/nemmtor)
|
package/dist/main.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import*as
|
|
3
|
-
|
|
2
|
+
import*as ft from"@effect/platform-node/NodeContext";import*as pt from"@effect/platform-node/NodeRuntime";import*as ut from"effect/Effect";import*as mt from"effect/Layer";import*as gt from"effect/Logger";import*as St from"effect/LogLevel";import*as J from"@effect/cli/Command";import*as r from"@effect/cli/Options";import*as ne from"effect/Layer";import{Project as xt}from"ts-morph";import*as Ie from"@effect/platform/FileSystem";import*as ke from"@effect/platform/Path";import*as m from"effect/Effect";import*as D from"effect/Match";import*as Ye from"effect/Option";import*as H from"effect/Schema";import*as Ce from"@effect/platform/FileSystem";import*as je from"@effect/platform/Path";import*as Ge from"effect/Context";import*as x from"effect/Effect";import*as k from"effect/Option";import*as i from"effect/Schema";var C={jsdocTag:"JSDoc tag used to mark types for data building generation.",inlineDefaultJsdocTag:"JSDoc tag used to set default value of given field.",withNestedbuilders:"When set to true ts-databuilders will use nested builders approach.",outputDir:"Output directory for generated builders.",include:"Glob pattern for files included while searching for jsdoc tag.",fileSuffix:"File suffix for created builder files.",fileCase:"Naming convention for generated builder file",builderSuffix:"Suffix for generated classes.",defaults:"Default values to be used in data builder constructor.",defaultString:"Default string value to be used in data builder constructor.",defaultNumber:"Default number value to be used in data builder constructor.",defaultBoolean:"Default boolean value to be used in data builder constructor."};import*as ue from"effect/Effect";var R=class extends ue.Service()("@TSDataBuilders/Process",{succeed:{cwd:ue.sync(()=>process.cwd())}}){};var Tt=e=>e!==void 0,re=e=>Object.fromEntries(Object.entries(e).filter(([o,c])=>Tt(c)));var Oe="ts-databuilders.json",Et=i.Struct({jsdocTag:i.NonEmptyTrimmedString,inlineDefaultJsdocTag:i.NonEmptyTrimmedString,withNestedBuilders:i.Boolean,outputDir:i.NonEmptyTrimmedString,include:i.NonEmptyTrimmedString,fileSuffix:i.NonEmptyTrimmedString,fileCase:i.Literal("kebab","camel","pascal"),builderSuffix:i.NonEmptyTrimmedString,defaults:i.Struct({string:i.String,number:i.Number,boolean:i.Boolean})}),j=Et.make({jsdocTag:"DataBuilder",inlineDefaultJsdocTag:"DataBuilderDefault",withNestedBuilders:!0,outputDir:"generated/builders",include:"src/**/*.ts{,x}",fileSuffix:".builder",fileCase:"kebab",builderSuffix:"Builder",defaults:{string:"",number:0,boolean:!1}}),De=i.Struct({$schema:i.optional(i.String),jsdocTag:i.String.pipe(i.annotations({description:C.jsdocTag})),inlineDefaultJsdocTag:i.String.pipe(i.annotations({description:C.inlineDefaultJsdocTag})),withNestedBuilders:i.Boolean.pipe(i.annotations({description:C.withNestedbuilders})),outputDir:i.String.pipe(i.annotations({description:C.outputDir})),include:i.String.pipe(i.annotations({description:C.include})),fileSuffix:i.String.pipe(i.annotations({description:C.fileSuffix})),fileCase:i.Literal("kebab","camel","pascal").pipe(i.annotations({description:C.fileCase})),builderSuffix:i.String.pipe(i.annotations({description:C.builderSuffix})),defaults:i.Struct({string:i.String.pipe(i.annotations({description:C.defaultString})),number:i.Number.pipe(i.annotations({description:C.defaultNumber})),boolean:i.Boolean.pipe(i.annotations({description:C.defaultBoolean}))}).pipe(i.partial,i.annotations({description:C.defaults}))}).pipe(i.partial),L=class extends Ge.Tag("Configuration")(){},G=i.Struct({jsdocTag:i.NonEmptyTrimmedString,inlineDefaultJsdocTag:i.NonEmptyTrimmedString,withNestedBuilders:i.BooleanFromString,outputDir:i.NonEmptyTrimmedString,include:i.NonEmptyTrimmedString,fileSuffix:i.NonEmptyTrimmedString,fileCase:i.Literal("kebab","camel","pascal"),builderSuffix:i.NonEmptyTrimmedString,defaultString:i.String,defaultNumber:i.NumberFromString,defaultBoolean:i.BooleanFromString}),_e=e=>x.gen(function*(){yield*x.logDebug("[Configuration]: Loading configuration");let c=yield*(yield*R).cwd,d=(yield*je.Path).join(c,Oe),a=yield*Ot(d),E=yield*Nt({fromCLI:e,fromConfigFile:a});return L.of(E)}),Nt=e=>x.gen(function*(){let o=Ct(e),c=k.flatMap(e.fromConfigFile,E=>k.fromNullable(E.defaults)).pipe(k.map(E=>re(E)),k.getOrElse(()=>({}))),f=re({string:e.fromCLI.defaultString.pipe(k.getOrUndefined),number:e.fromCLI.defaultNumber.pipe(k.getOrUndefined),boolean:e.fromCLI.defaultBoolean.pipe(k.getOrUndefined)}),d={...c,...f},a={builderSuffix:yield*o("builderSuffix"),include:yield*o("include"),withNestedBuilders:yield*o("withNestedBuilders"),fileSuffix:yield*o("fileSuffix"),fileCase:yield*o("fileCase"),jsdocTag:yield*o("jsdocTag"),inlineDefaultJsdocTag:yield*o("inlineDefaultJsdocTag"),outputDir:yield*o("outputDir"),defaults:{...j.defaults,...d}};return yield*x.logDebug(`[Configuration]: Resolving config with value: ${JSON.stringify(a,null,4)}`),a}),Ct=e=>o=>e.fromCLI[o].pipe(x.orElse(()=>k.flatMap(e.fromConfigFile,c=>k.fromNullable(c[o]))),x.orElseSucceed(()=>j[o])),Ot=e=>x.gen(function*(){let o=yield*Ce.FileSystem;if(yield*x.orDie(o.exists(e))){yield*x.logDebug("[Configuration]: Found config file - attempting to read it");let f=yield*Dt(e),d=yield*i.decodeUnknown(De)(f);return k.some(d)}else return yield*x.logDebug("[Configuration]: No config file found"),k.none()}),Dt=e=>x.gen(function*(){let o=yield*Ce.FileSystem,c=yield*x.orDie(o.readFileString(e));return yield*x.try({try:()=>JSON.parse(c),catch:f=>`[FileSystem] Unable to read and parse JSON file from '${e}': ${String(f)}`})}).pipe(x.orDie);import*as B from"effect/Schema";var be=B.transform(B.String,B.String.pipe(B.brand("KebabCase")),{decode:e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z][a-z])/g,"$1-$2").replace(/_/g,"-").toLowerCase(),encode:e=>e}),we=B.transform(B.String,B.String.pipe(B.brand("PascalCase")),{decode:e=>e.split(/[-_\s]+/).flatMap(o=>o.split(/(?=[A-Z])/)).filter(Boolean).map(o=>o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()).join(""),encode:e=>e}),xe=B.transform(B.String,B.String.pipe(B.brand("CamelCase")),{decode:e=>e.split(/[-_\s]+/).flatMap(o=>o.split(/(?=[A-Z])/)).filter(Boolean).map((o,c)=>{let f=o.toLowerCase();return c===0?f:f.charAt(0).toUpperCase()+f.slice(1)}).join(""),encode:e=>e});import{randomUUID as wt}from"crypto";import*as me from"effect/Effect";var z=class extends me.Service()("@TSDataBuilders/IdGenerator",{succeed:{generateUuid:me.sync(()=>wt())}}){};var ge=class extends m.Service()("@TSDataBuilders/BuilderGenerator",{effect:m.gen(function*(){let o=yield*Ie.FileSystem,c=yield*ke.Path,f=yield*R,d=yield*L,a=yield*z,{fileSuffix:E,builderSuffix:O,defaults:g,fileCase:T}=d,u=m.fnUntraced(function*(n){return yield*{kebab:be.pipe(H.decode),pascal:we.pipe(H.decode),camel:xe.pipe(H.decode)}[T](n)}),s=n=>Ye.getOrUndefined(n.inlineDefault)??D.value(n).pipe(D.when({kind:"STRING"},()=>`"${g.string}"`),D.when({kind:"NUMBER"},()=>g.number),D.when({kind:"BOOLEAN"},()=>g.boolean),D.when({kind:"UNDEFINED"},()=>{}),D.when({kind:"BIGINT"},()=>"BigInt(0)"),D.when({kind:"SYMBOL"},()=>"Symbol('')"),D.when({kind:"ANY"},()=>{}),D.when({kind:"UNKNOWN"},()=>{}),D.when({kind:"NULL"},()=>null),D.when({kind:"DATE"},()=>"new Date()"),D.when({kind:"ARRAY"},()=>"[]"),D.when({kind:"LITERAL"},l=>l.literalValue),D.when({kind:"TYPE_CAST"},l=>s(l.baseTypeMetadata)),D.when({kind:"TUPLE"},l=>`[${l.members.map(P=>s(P)).map(P=>`${P}`).join(", ")}]`),D.when({kind:"TYPE_LITERAL"},l=>`{${Object.entries(l.metadata).filter(([P,{optional:y}])=>!y).map(([P,y])=>`${P}: ${s(y)}`).join(", ")}}`),D.when({kind:"RECORD"},l=>{if(l.keyType.kind==="STRING"||l.keyType.kind==="NUMBER")return"{}";let S=s(l.keyType),P=s(l.valueType);return`{${S}: ${P}}`}),D.when({kind:"UNION"},l=>{let P=l.members.slice().sort((y,N)=>{let I=Je.indexOf(y.kind),w=Je.indexOf(N.kind);return(I===-1?1/0:I)-(w===-1?1/0:w)})[0];return P?s(P):"never"}),D.when({kind:"BUILDER"},l=>`new ${l.name}${O}().build()`),D.exhaustive);return{generateBaseBuilder:m.fnUntraced(function*(){let n=c.join(yield*f.cwd,d.outputDir),l=c.resolve(n,`${yield*u("dataBuilder")}.ts`);yield*m.logDebug(`[Builders]: Creating base builder at ${l}`),yield*m.orDie(o.writeFileString(l,`${It}
|
|
3
|
+
`))}),generateBuilder:m.fnUntraced(function*(n){let l=new xt,S=n.name;yield*m.logDebug(`[Builders]: Creating builder for ${S}`);let P=c.join(yield*f.cwd,d.outputDir),y=c.resolve(P,`${yield*u(S)}${E}.ts`);yield*m.logDebug(`[Builders]: Creating builder content for ${S}`);let N=l.createSourceFile(`__temp_${yield*a.generateUuid}.ts`,"",{overwrite:!0}),I=c.resolve(n.path),w=c.relative(c.dirname(y),I).replace(/\.ts$/,"");if(N.addImportDeclaration({namedImports:[S],isTypeOnly:!0,moduleSpecifier:w}),N.addImportDeclaration({namedImports:["DataBuilder"],moduleSpecifier:"./data-builder"}),n.shape.kind!=="TYPE_LITERAL")return yield*m.dieMessage("[BuilderGenerator]: Expected root type to be type literal");let b=[...new Set(kt(n.shape.metadata))];yield*m.forEach(b,F=>be.pipe(H.decode)(F).pipe(m.andThen(A=>N.addImportDeclaration({namedImports:[`${F}${O}`],moduleSpecifier:`./${A}${E}`}))),{concurrency:"unbounded"});let v=Object.entries(n.shape.metadata).filter(([F,{optional:A}])=>!A).map(([F,A])=>`${F}: ${A.kind==="TYPE_CAST"?`${s(A)} as ${S}['${F}']`:s(A)}`),Z=yield*m.all(Object.entries(n.shape.metadata).map(([F,{optional:A,kind:fe}])=>Pt({fieldName:F,optional:A,typeName:S,isNestedBuilder:fe==="BUILDER"})),{concurrency:"unbounded"}),W=`{
|
|
4
|
+
${v.join(`,
|
|
4
5
|
`)}
|
|
5
|
-
}`;
|
|
6
|
+
}`;N.addClass({name:`${S}${O}`,isExported:!0,extends:`DataBuilder<${S}>`,methods:[{name:"constructor",statements:[`super(${W});`]},...Z]}),yield*m.logDebug(`[Builders]: Saving builder content at ${y}`),yield*o.writeFileString(y,`${N.getText()}
|
|
7
|
+
`)})}}),dependencies:[z.Default]}){},Je=["UNDEFINED","BOOLEAN","NUMBER","STRING","DATE","LITERAL","TYPE_LITERAL","ARRAY","TUPLE","RECORD"],It=`export abstract class DataBuilder<T> {
|
|
6
8
|
private data: T;
|
|
7
9
|
|
|
8
10
|
constructor(initialData: T) {
|
|
@@ -18,4 +20,5 @@ import*as We from"@effect/platform-node/NodeContext";import*as Ge from"@effect/p
|
|
|
18
20
|
return this;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
`;function rt(t){let n=[];function i(e){switch(e.kind){case"BUILDER":n.push(e.name);break;case"TYPE_LITERAL":Object.values(e.metadata).forEach(i);break;case"UNION":case"TUPLE":e.members.forEach(i);break;case"RECORD":i(e.keyType),i(e.valueType);break}}return Object.values(t).forEach(i),n}class I extends F.Service()("@TSDataBuilders/Builders",{effect:F.gen(function*(){let t=yield*ke.FileSystem,n=yield*X,{outputDir:i}=yield*x;return{create:F.fnUntraced(function*(e){if(yield*t.exists(i))yield*t.remove(i,{recursive:!0});yield*t.makeDirectory(i,{recursive:!0}),yield*n.generateBaseBuilder();let r=e.map((l)=>l.name),p=r.filter((l,o)=>r.indexOf(l)!==o),s=[...new Set(p)];if(p.length>0)return yield*F.dieMessage(`Duplicated builders: ${s.join(", ")}`);yield*F.all(e.map((l)=>n.generateBuilder(l)),{concurrency:"unbounded"})})}}),dependencies:[X.Default]}){}import*as f from"@effect/cli/Options";import*as R from"effect/HashMap";import*as ee from"effect/Option";import*as P from"effect/Schema";var nt=f.text("jsdocTag").pipe(f.withDescription("JSDoc tag used to mark types for data building generation."),f.withSchema($.fields.jsdocTag),f.optional),ot=f.text("output-dir").pipe(f.withAlias("o"),f.withDescription("Output directory for generated builders."),f.withSchema($.fields.outputDir),f.optional),it=f.text("include").pipe(f.withAlias("i"),f.withDescription("Glob pattern for files included while searching for jsdoc tag."),f.withSchema($.fields.include),f.optional),at=f.text("file-suffix").pipe(f.withDescription("File suffix for created builder files."),f.withSchema($.fields.fileSuffix),f.optional),st=f.text("builder-suffix").pipe(f.withDescription("Suffix for generated classes."),f.withSchema($.fields.builderSuffix),f.optional),ct=f.keyValueMap("defaults").pipe(f.withDescription("Default values to be used in data builder constructor."),f.withSchema(P.HashMapFromSelf({key:P.Literal("string","number","boolean"),value:P.String}).pipe(P.transform($.fields.defaults,{decode:(t)=>{return{string:t.pipe(R.get("string"),ee.getOrElse(()=>"")),number:t.pipe(R.get("number"),ee.getOrElse(()=>"0")),boolean:t.pipe(R.get("boolean"),ee.getOrElse(()=>"false"))}},encode:(t)=>{return R.make(["string",t.string],["number",t.number],["boolean",t.boolean])},strict:!1}))),f.optional),Be={jsdocTag:nt,outputDir:ot,include:it,fileSuffix:at,builderSuffix:st,defaults:ct};import*as M from"effect/Chunk";import*as D from"effect/Effect";import*as $e from"effect/Function";import*as j from"effect/Option";import*as re from"effect/Stream";import*as Ne from"effect/Data";import*as De from"effect/Effect";import*as Fe from"effect/Stream";import{glob as lt}from"glob";class U extends De.Service()("@TSDataBuilders/TreeWalker",{succeed:{walk:(t)=>{return Fe.fromAsyncIterable(lt.stream(t,{cwd:".",nodir:!0}),(n)=>new ce({cause:n}))}}}){}class ce extends Ne.TaggedError("TreeWalkerError"){}import{FileSystem as dt}from"@effect/platform";import*as v from"effect/Effect";import*as L from"effect/Stream";class te extends v.Service()("@TSDataBuilders/FileContentChecker",{effect:v.gen(function*(){let t=yield*dt.FileSystem,n=new TextDecoder;return{check:v.fnUntraced(function*(i){let{content:e,filePath:c}=i;return yield*t.stream(c,{chunkSize:16384}).pipe(L.map((s)=>n.decode(s,{stream:!0})),L.mapAccum("",(s,l)=>{let o=s+l;return[o.slice(-e.length+1),o.includes(e)]}),L.find(Boolean),L.runCollect)})}})}){}class _ extends D.Service()("@TSDataBuilders/Finder",{effect:D.gen(function*(){let t=yield*te,{include:n,jsdocTag:i}=yield*x,e=`@${i}`;return{find:D.fnUntraced(function*(){return yield*(yield*U).walk(n).pipe(re.mapEffect((s)=>t.check({filePath:s,content:e}).pipe(D.map(M.map((l)=>l?j.some(s):j.none()))),{concurrency:"unbounded"}),re.runCollect,D.map(M.flatMap($e.identity)),D.map(M.filter((s)=>j.isSome(s))),D.map(M.map((s)=>s.value)))})}}),dependencies:[te.Default]}){}import*as Pe from"@effect/platform/FileSystem";import*as W from"effect/Data";import*as S from"effect/Effect";import*as q from"effect/Either";import{Project as pt,SyntaxKind as ie}from"ts-morph";import{randomUUID as mt}from"node:crypto";import*as V from"effect/Data";import*as m from"effect/Effect";import*as u from"effect/Match";import*as Oe from"effect/Option";import{Node as ft,SyntaxKind as E}from"ts-morph";class oe extends m.Service()("@TSDataBuilders/TypeNodeParser",{effect:m.gen(function*(){let{jsdocTag:t}=yield*x,n=(e)=>m.gen(function*(){let{type:c,contextNode:r,optional:p}=e,s=c.getProperties();if(!c.isObject()||s.length===0)return yield*new we({raw:c.getText(),kind:r.getKind()});let l={};for(let o of s){let a=o.getName(),g=o.getTypeAtLocation(r),y=o.isOptional(),h=r.getProject().createSourceFile(`__temp_${mt()}.ts`,`type __T = ${g.getText()}`,{overwrite:!0}),k=h.getTypeAliasOrThrow("__T").getTypeNodeOrThrow(),N=yield*m.suspend(()=>i({typeNode:k,optional:y}));l[a]=N,r.getProject().removeSourceFile(h)}return{kind:"TYPE_LITERAL",metadata:l,optional:p}}),i=(e)=>m.gen(function*(){let{typeNode:c,optional:r}=e,p=c.getKind(),s=u.value(p).pipe(u.when(u.is(E.StringKeyword),()=>m.succeed({kind:"STRING",optional:r})),u.when(u.is(E.NumberKeyword),()=>m.succeed({kind:"NUMBER",optional:r})),u.when(u.is(E.BooleanKeyword),()=>m.succeed({kind:"BOOLEAN",optional:r})),u.when(u.is(E.UndefinedKeyword),()=>m.succeed({kind:"UNDEFINED",optional:r})),u.when(u.is(E.ArrayType),()=>m.succeed({kind:"ARRAY",optional:r})),u.when(u.is(E.LiteralType),()=>m.succeed({kind:"LITERAL",literalValue:c.asKindOrThrow(E.LiteralType).getLiteral().getText(),optional:r})),u.when(u.is(E.TypeLiteral),()=>m.gen(function*(){let a=c.asKindOrThrow(E.TypeLiteral).getMembers();return{kind:"TYPE_LITERAL",metadata:yield*m.reduce(a,{},(y,h)=>m.gen(function*(){if(!h.isKind(E.PropertySignature))return y;let k=h.getTypeNode();if(!k)return y;let N=h.getNameNode().getText(),Z=h.hasQuestionToken(),b=yield*m.suspend(()=>i({typeNode:k,optional:Z}));return{...y,[N]:b}})),optional:r}})),u.when(u.is(E.ImportType),()=>m.gen(function*(){let o=c.asKindOrThrow(E.ImportType),a=o.getType(),g=a.getSymbol();if(!g)throw Error("TODO: missing symbol");let y=g.getDeclarations();if(y&&y.length>1)return yield*new le;let[h]=y;if(!h)return yield*new de;return yield*n({type:a,contextNode:o,optional:r})})),u.when(u.is(E.TupleType),()=>m.gen(function*(){let a=c.asKindOrThrow(E.TupleType).getElements(),g=yield*m.all(a.map((y)=>m.suspend(()=>i({typeNode:y,optional:!1}))));return{kind:"TUPLE",optional:r,members:g}})),u.when(u.is(E.TypeReference),()=>m.gen(function*(){let o=c.asKindOrThrow(E.TypeReference),a=o.getTypeName().getText();if(a==="Date")return{kind:"DATE",optional:r};if(a==="Array")return{kind:"ARRAY",optional:r};let g=o.getTypeArguments();if(a==="Record"){let[B,H]=g;if(!B||!H)return yield*new ne({kind:p,raw:c.getText()});let Ke=yield*m.suspend(()=>i({typeNode:B,optional:!1})),Ze=yield*m.suspend(()=>i({typeNode:H,optional:!1}));return{kind:"RECORD",keyType:Ke,valueType:Ze,optional:r}}if(["Pick","Omit","Partial","Required","Readonly","Extract","NonNullable"].includes(a))return yield*n({type:o.getType(),contextNode:o,optional:r});let h=o.getType().getAliasSymbol();if(!h)return yield*n({type:o.getType(),contextNode:o,optional:r});let k=h.getDeclarations();if(k&&k.length>1)return yield*new le;let[N]=k;if(!N)return yield*new de;let Z=h?.getJsDocTags().map((B)=>B.getName()).includes(t);if(!ft.isTypeAliasDeclaration(N))throw Error("TODO: for non-type-alias declarations (interfaces, etc.)");let b=N.getTypeNode();if(!b)return yield*new ne({kind:p,raw:c.getText()});if(!Z)return yield*m.suspend(()=>i({typeNode:b,optional:r}));return{kind:"BUILDER",name:N.getName(),optional:r}})),u.when(u.is(E.UnionType),()=>m.gen(function*(){let o=yield*m.all(c.asKindOrThrow(E.UnionType).getTypeNodes().map((a)=>m.suspend(()=>i({typeNode:a,optional:!1}))));return{kind:"UNION",optional:r,members:o}})),u.when(u.is(E.IntersectionType),()=>m.gen(function*(){let a=c.asKindOrThrow(E.IntersectionType).getTypeNodes(),g=[E.StringKeyword,E.NumberKeyword,E.BooleanKeyword],y=a.find((h)=>g.includes(h.getKind()));if(y&&a.length>1)return{kind:"TYPE_CAST",baseTypeMetadata:yield*m.suspend(()=>i({typeNode:y,optional:!1})),optional:r};throw Error("TODO: handle it")})),u.option);if(Oe.isNone(s))return yield*new ne({kind:p,raw:c.getText()});return yield*s.value});return{generateMetadata:i}})}){}class ne extends V.TaggedError("UnsupportedSyntaxKindError"){}class le extends V.TaggedError("MultipleSymbolDeclarationsError"){}class de extends V.TaggedError("MissingSymbolDeclarationError"){}class we extends V.TaggedError("CannotBuildTypeReferenceMetadata"){}class G extends S.Service()("@TSDataBuilders/Parser",{effect:S.gen(function*(){let t=yield*Pe.FileSystem,n=yield*oe,{jsdocTag:i}=yield*x;return{generateBuildersMetadata:S.fnUntraced(function*(e){let c=yield*t.readFileString(e),r=yield*S.try({try:()=>{return new pt().createSourceFile(e,c,{overwrite:!0}).getTypeAliases().filter((g)=>g.getJsDocs().flatMap((y)=>y.getTags().flatMap((h)=>h.getTagName())).includes(i)).map((g)=>{let y=g.getName();if(!g.isExported())return q.left(new Ae({path:e,typeName:y}));let h=g.getTypeNode();if(!(h?.isKind(ie.TypeLiteral)||h?.isKind(ie.TypeReference)))return q.left(new Me({path:e,typeName:g.getName()}));return q.right({name:g.getName(),node:h})}).filter(Boolean)},catch:(l)=>new Le({cause:l})}),p=yield*S.all(r.map((l)=>l));return yield*S.all(p.map(({name:l,node:o})=>n.generateMetadata({typeNode:o,optional:!1}).pipe(S.map((a)=>({name:l,shape:a,path:e})),S.catchTags({UnsupportedSyntaxKindError:(a)=>S.fail(new Ie({kind:a.kind,raw:a.raw,path:e,typeName:l})),CannotBuildTypeReferenceMetadata:(a)=>S.fail(new Re({kind:a.kind,raw:a.raw,path:e,typeName:l}))}))))},S.catchTags({ParserError:(e)=>S.die(e),UnexportedDatabuilderError:(e)=>S.dieMessage(`[Parser]: Unexported databuilder ${e.typeName} at ${e.path}`),RichUnsupportedSyntaxKindError:(e)=>S.dieMessage(`[Parser]: Unsupported syntax kind of id: ${e.kind} with raw type: ${e.raw} found in type ${e.typeName} in file ${e.path}`),RichCannotBuildTypeReferenceMetadata:(e)=>S.dieMessage(`[Parser]: Cannot build type reference metadata with kind of id: ${e.kind} with raw type: ${e.raw} found in type ${e.typeName} in file ${e.path}. Is it a root of databuilder?`),UnsupportedBuilderTypeError:(e)=>S.dieMessage(`[Parser]: Unsupported builder type ${e.typeName} in file ${e.path}.`)}))}}),dependencies:[oe.Default]}){}class Le extends W.TaggedError("ParserError"){}class Ae extends W.TaggedError("UnexportedDatabuilderError"){}class Me extends W.TaggedError("UnsupportedBuilderTypeError"){}class Ie extends W.TaggedError("RichUnsupportedSyntaxKindError"){}class Re extends W.TaggedError("RichCannotBuildTypeReferenceMetadata"){}import*as Ue from"effect/Chunk";import*as Y from"effect/Effect";import*as ve from"effect/Function";var je=Y.gen(function*(){let t=yield*_,n=yield*G,i=yield*I,e=yield*t.find(),c=yield*Y.all(Ue.map(e,(r)=>n.generateBuildersMetadata(r)),{concurrency:"unbounded"}).pipe(Y.map((r)=>r.flatMap(ve.identity)));if(c.length===0)return;yield*i.create(c)});var ut=A.make("ts-databuilders",Be),_e=ut.pipe(A.withHandler(()=>je),A.provide((t)=>K.mergeAll(_.Default,G.Default,I.Default,U.Default).pipe(K.provide(K.effect(x,Ce(t))))),A.run({name:"Typescript Databuilders generator",version:"v0.0.1"}));var yt=Ye.mergeAll(ue,We.layer);_e(process.argv).pipe(ht.provide(yt),Ge.runMain);
|
|
23
|
+
`;function kt(e){let o=[];function c(f){switch(f.kind){case"BUILDER":o.push(f.name);break;case"TYPE_LITERAL":Object.values(f.metadata).forEach(c);break;case"UNION":case"TUPLE":f.members.forEach(c);break;case"RECORD":c(f.keyType),c(f.valueType);break}}return Object.values(e).forEach(c),o}var Pt=e=>m.gen(function*(){let{fieldName:o,optional:c,typeName:f,isNestedBuilder:d}=e,a=o.replaceAll("'","").replaceAll('"',""),E=yield*xe.pipe(H.decode)(a),O=`with${yield*we.pipe(H.decode)(a)}`,g=[`return this.with({ ${o}: ${E} });`],T=[`return this.with({ ${o}: ${E}.build() });`],u=d?T:g,s=[`if (!${E}) {`,` const { "${a}": _unused, ...rest } = this.build();`," return this.with(rest);","}"],n=c?[...s,...u]:u,l=`${f}['${a}']`;return{name:O,isPublic:!0,parameters:[{name:E,type:d?`DataBuilder<${l}>`:l}],statements:n}}),Q=class extends m.Service()("@TSDataBuilders/BuildersGenerator",{effect:m.gen(function*(){let o=yield*Ie.FileSystem,c=yield*ge,f=yield*R,d=yield*ke.Path,a=yield*L;return{create:m.fnUntraced(function*(E){let O=d.join(yield*f.cwd,a.outputDir);(yield*m.orDie(o.exists(O)))&&(yield*m.logDebug(`[Builders]: Removing already existing output directory at ${O}`),yield*m.orDie(o.remove(O,{recursive:!0}))),yield*m.logDebug(`[Builders]: Creating output directory at ${O}`),yield*m.orDie(o.makeDirectory(O,{recursive:!0})),yield*c.generateBaseBuilder();let T=E.map(n=>n.name),u=T.filter((n,l)=>T.indexOf(n)!==l),s=[...new Set(u)];if(u.length>0)return yield*m.dieMessage(`Duplicated builders: ${s.join(", ")}`);yield*m.all(E.map(n=>c.generateBuilder(n)),{concurrency:"unbounded"})})}}),dependencies:[ge.Default]}){};import*as Ve from"@effect/platform/FileSystem";import*as Ze from"@effect/platform/Path";import*as ze from"effect/Effect";import*as U from"effect/Option";import*as qe from"effect/Schema";var He=e=>ze.gen(function*(){let o=yield*R,c=yield*Ve.FileSystem,f=yield*o.cwd,a=(yield*Ze.Path).join(f,Oe),E=re({string:e.defaultString.pipe(U.getOrUndefined),number:e.defaultNumber.pipe(U.getOrUndefined),boolean:e.defaultBoolean.pipe(U.getOrUndefined)}),O=yield*qe.decode(De)({$schema:"https://raw.githubusercontent.com/nemmtor/ts-databuilders/refs/heads/main/schema.json",builderSuffix:e.builderSuffix.pipe(U.getOrElse(()=>j.builderSuffix)),fileSuffix:e.fileSuffix.pipe(U.getOrElse(()=>j.fileSuffix)),fileCase:e.fileCase.pipe(U.getOrElse(()=>j.fileCase)),include:e.include.pipe(U.getOrElse(()=>j.include)),jsdocTag:e.jsdocTag.pipe(U.getOrElse(()=>j.jsdocTag)),inlineDefaultJsdocTag:e.inlineDefaultJsdocTag.pipe(U.getOrElse(()=>j.inlineDefaultJsdocTag)),withNestedBuilders:e.withNestedBuilders.pipe(U.getOrElse(()=>j.withNestedBuilders)),outputDir:e.outputDir.pipe(U.getOrElse(()=>j.outputDir)),defaults:{...j.defaults,...E}});yield*c.writeFileString(a,`${JSON.stringify(O,null,2)}
|
|
24
|
+
`)});import*as ee from"effect/Chunk";import*as M from"effect/Effect";import*as ye from"effect/Option";import*as he from"effect/Stream";import*as Qe from"@effect/platform/FileSystem";import*as Xe from"effect/Chunk";import*as Y from"effect/Effect";import*as _ from"effect/Stream";var se=class extends Y.Service()("@TSDataBuilders/FileContentChecker",{effect:Y.gen(function*(){let o=yield*Qe.FileSystem,c=new TextDecoder;return{check:Y.fnUntraced(function*(f){let{content:d,filePath:a}=f;return yield*Y.logDebug(`[FileContentChecker](${a}): Checking file content`),yield*_.orDie(o.stream(a,{chunkSize:16*1024})).pipe(_.map(g=>c.decode(g,{stream:!0})),_.mapAccum("",(g,T)=>{let u=g+T;return[u.slice(-d.length+1),u.includes(d)]}),_.find(g=>!!g),_.tap(()=>Y.logDebug(`[FileContentChecker](${a}): found expected content`)),_.runCollect,Y.map(g=>g.pipe(Xe.get(0))))})}})}){};import*as et from"effect/Data";import*as q from"effect/Effect";import*as tt from"effect/Stream";import{glob as Ft}from"glob";import*as Se from"effect/Effect";var ce=class extends Se.Service()("@TSDataBuilders/Glob",{succeed:{iterate:o=>Se.sync(()=>Ft.iterate(o.path,{cwd:o.cwd,nodir:!0}))}}){};var de=class extends q.Service()("@TSDataBuilders/TreeWalker",{effect:q.gen(function*(){let o=yield*ce,c=yield*R;return{walk:q.fnUntraced(function*(f){let d=yield*c.cwd;return yield*q.logDebug(`[TreeWalker]: Walking path: ${d}/${f}`),tt.fromAsyncIterable(yield*o.iterate({path:f,cwd:d}),a=>new Pe({cause:a}))})}}),dependencies:[ce.Default]}){},Pe=class extends et.TaggedError("TreeWalkerError"){};var X=class extends M.Service()("@TSDataBuilders/Finder",{effect:M.gen(function*(){let o=yield*se,c=yield*de,{include:f,jsdocTag:d}=yield*L,a=`@${d}`;return{find:M.gen(function*(){yield*M.logDebug("[Finder]: Attempting to find files with builders");let O=yield*(yield*c.walk(f)).pipe(he.mapEffect(g=>o.check({filePath:g,content:a}).pipe(M.map(T=>T.pipe(ye.map(()=>g)))),{concurrency:"unbounded"}),he.runCollect,M.map(ee.filter(g=>ye.isSome(g))),M.map(ee.map(g=>g.value)));return yield*M.logDebug(`[Finder]: Found builders in files: ${O.pipe(ee.toArray).join(", ")}`),O}).pipe(M.catchTag("TreeWalkerError",E=>M.die(E)))}}),dependencies:[de.Default,se.Default]}){};import{Node as Rt,Project as Lt,SyntaxKind as h}from"ts-morph";import*as nt from"@effect/platform/FileSystem";import*as V from"effect/Data";import*as t from"effect/Effect";import*as le from"effect/Either";import*as p from"effect/Match";import*as K from"effect/Option";var Te=class extends t.Service()("@TSDataBuilders/TypeNodeParser",{effect:t.gen(function*(){let{jsdocTag:o,inlineDefaultJsdocTag:c,withNestedBuilders:f}=yield*L,d=yield*z,a=t.fnUntraced(function*(T){let u=T.getJsDocs();for(let s of u){let l=s.getTags().find(S=>S.getTagName()===c);if(l){let S=l.getComment();if(typeof S=="string")return K.some(S.trim())}}return K.none()}),E=t.fnUntraced(function*(T){let{type:u,contextNode:s}=T,n=u.getProperties(),l={};for(let S of n){let P=S.getName(),y=S.getTypeAtLocation(s),N=S.isOptional(),I=s.getProject().createSourceFile(`__temp_${yield*d.generateUuid}.ts`,`type __T = ${y.getText()}`,{overwrite:!0}),w=I.getTypeAliasOrThrow("__T").getTypeNodeOrThrow(),b=yield*t.suspend(()=>g({typeNode:w,optional:N,inlineDefault:K.none()}));l[P]=b,s.getProject().removeSourceFile(I)}return l}),O=t.fnUntraced(function*(T){let{type:u,contextNode:s,optional:n,inlineDefault:l}=T;return!u.isObject()||u.getProperties().length===0?yield*new Fe({raw:u.getText(),kind:s.getKind()}):{kind:"TYPE_LITERAL",metadata:yield*E({type:u,contextNode:s}),inlineDefault:l,optional:n}}),g=T=>t.gen(function*(){let{typeNode:u,optional:s,inlineDefault:n}=T,l=u.getKind(),S=p.value(l).pipe(p.when(p.is(h.StringKeyword),()=>t.succeed({kind:"STRING",inlineDefault:n,optional:s})),p.when(p.is(h.NumberKeyword),()=>t.succeed({kind:"NUMBER",inlineDefault:n,optional:s})),p.when(p.is(h.BooleanKeyword),()=>t.succeed({kind:"BOOLEAN",inlineDefault:n,optional:s})),p.when(p.is(h.UndefinedKeyword),()=>t.succeed({kind:"UNDEFINED",inlineDefault:n,optional:s})),p.when(p.is(h.BigIntKeyword),()=>t.succeed({kind:"BIGINT",inlineDefault:n,optional:s})),p.when(p.is(h.SymbolKeyword),()=>t.succeed({kind:"SYMBOL",inlineDefault:n,optional:s})),p.when(p.is(h.AnyKeyword),()=>t.succeed({kind:"ANY",inlineDefault:n,optional:s})),p.when(p.is(h.UnknownKeyword),()=>t.succeed({kind:"UNKNOWN",inlineDefault:n,optional:s})),p.when(p.is(h.ArrayType),()=>t.succeed({kind:"ARRAY",inlineDefault:n,optional:s})),p.when(p.is(h.LiteralType),()=>{let y=u.asKindOrThrow(h.LiteralType).getLiteral().getText();return y==="null"?t.succeed({kind:"NULL",inlineDefault:n,optional:s}):t.succeed({kind:"LITERAL",inlineDefault:n,literalValue:y,optional:s})}),p.when(p.is(h.TypeLiteral),()=>t.gen(function*(){let N=u.asKindOrThrow(h.TypeLiteral).getMembers(),I=yield*t.reduce(N,{},(w,b)=>t.gen(function*(){if(!b.isKind(h.PropertySignature))return w;let v=b.getTypeNode();if(!v)return w;let Z=b.getNameNode().getText(),W=b.hasQuestionToken(),F=yield*a(b),A=yield*t.suspend(()=>g({typeNode:v,optional:W,inlineDefault:F}));return{...w,[Z]:A}}));return{kind:"TYPE_LITERAL",inlineDefault:n,metadata:I,optional:s}})),p.when(p.is(h.ImportType),()=>t.gen(function*(){let y=u.asKindOrThrow(h.ImportType),N=y.getType(),I=N.getSymbol(),w=N.getText();if(!I)return yield*new Le({raw:w});let b=I.getDeclarations();if(b&&b.length>1)return yield*new Ne({raw:w});let[v]=b;return v?yield*O({type:N,contextNode:y,inlineDefault:n,optional:s}):yield*new Ee({raw:w})})),p.when(p.is(h.TupleType),()=>t.gen(function*(){let N=u.asKindOrThrow(h.TupleType).getElements(),I=yield*t.all(N.map(w=>t.suspend(()=>g({typeNode:w,optional:!1,inlineDefault:K.none()}))),{concurrency:"unbounded"});return{kind:"TUPLE",inlineDefault:n,optional:s,members:I}})),p.when(p.is(h.TypeReference),()=>t.gen(function*(){let y=u.asKindOrThrow(h.TypeReference),N=y.getTypeName().getText();if(N==="Date")return{kind:"DATE",optional:s,inlineDefault:n};if(N==="Array")return{kind:"ARRAY",optional:s,inlineDefault:n};let I=y.getTypeArguments();if(N==="Record"){let[pe,Ue]=I;if(!pe||!Ue)return yield*new te({kind:l,raw:u.getText()});let yt=yield*t.suspend(()=>g({typeNode:pe,optional:!1,inlineDefault:K.none()})),ht=yield*t.suspend(()=>g({typeNode:Ue,optional:!1,inlineDefault:K.none()}));return{kind:"RECORD",keyType:yt,valueType:ht,optional:s,inlineDefault:n}}if(["Pick","Omit","Partial","Required","Readonly","Extract","NonNullable"].includes(N))return yield*O({type:y.getType(),contextNode:y,optional:s,inlineDefault:n});let b=y.getType(),v=b.getText(),Z=b.getAliasSymbol();if(!Z)return yield*O({type:b,contextNode:y,optional:s,inlineDefault:n});let W=Z.getDeclarations();if(W&&W.length>1)return yield*new Ne({raw:v});let[F]=W;if(!F)return yield*new Ee({raw:v});let A=Z?.getJsDocTags().map(pe=>pe.getName()).includes(o);if(!Rt.isTypeAliasDeclaration(F))return yield*new Me;let fe=F.getTypeNode();return fe?!A||!f?yield*t.suspend(()=>g({typeNode:fe,optional:s,inlineDefault:n})):{kind:"BUILDER",name:F.getName(),inlineDefault:n,optional:s}:yield*new te({kind:l,raw:v})})),p.when(p.is(h.UnionType),()=>t.gen(function*(){let y=yield*t.all(u.asKindOrThrow(h.UnionType).getTypeNodes().map(N=>t.suspend(()=>g({typeNode:N,optional:!1,inlineDefault:K.none()}))),{concurrency:"unbounded"});return{kind:"UNION",optional:s,members:y,inlineDefault:n}})),p.when(p.is(h.IntersectionType),()=>t.gen(function*(){let y=u.asKindOrThrow(h.IntersectionType),N=y.getTypeNodes(),I=[h.StringKeyword,h.NumberKeyword,h.BooleanKeyword],w=N.find(W=>I.includes(W.getKind()));if(w&&N.length>1)return{kind:"TYPE_CAST",baseTypeMetadata:yield*t.suspend(()=>g({typeNode:w,optional:!1,inlineDefault:n})),inlineDefault:n,optional:s};let b=y.getType();return b.getProperties().length===0?yield*new te({kind:l,raw:u.getText()}):{kind:"TYPE_LITERAL",metadata:yield*E({type:b,contextNode:y}),inlineDefault:n,optional:s}})),p.option);return K.isNone(S)?yield*new te({kind:l,raw:u.getText()}):yield*S.value});return{generateMetadata:g}}),dependencies:[z.Default]}){},ie=class extends t.Service()("@TSDataBuilders/Parser",{effect:t.gen(function*(){let o=yield*nt.FileSystem,c=yield*Te,{jsdocTag:f}=yield*L;return{generateBuildersMetadata:d=>t.gen(function*(){yield*t.logDebug(`[Parser](${d}): Generating builder metadata`),yield*t.logDebug(`[Parser](${d}): Reading source code`);let a=yield*t.orDie(o.readFileString(d)),E=yield*t.try({try:()=>new Lt().createSourceFile(d,a,{overwrite:!0}).getTypeAliases().filter(n=>n.getJsDocs().flatMap(l=>l.getTags().flatMap(S=>S.getTagName())).includes(f)).map(n=>{let l=n.getName();if(!n.isExported())return le.left(new Ae({typeName:l}));let S=n.getTypeNode();return S?.isKind(h.TypeLiteral)||S?.isKind(h.TypeReference)?le.right({name:n.getName(),node:S}):le.left(new Re({typeName:n.getName()}))}).filter(Boolean),catch:T=>new Be({cause:T})}),O=yield*t.all(E.map(T=>T),{concurrency:"unbounded"});return yield*t.logDebug(`[Parser](${d}): Generating metadata for types: ${O.map(({name:T})=>T).join(", ")}`),yield*t.all(O.map(({name:T,node:u})=>c.generateMetadata({typeNode:u,optional:!1,inlineDefault:K.none()}).pipe(t.tap(()=>t.logDebug(`[Parser](${d}): Finished generating metadata for type: ${T}`)),t.map(s=>({name:T,shape:s,path:d})))),{concurrency:"unbounded"})}).pipe(t.catchTags({ParserError:a=>t.die(a),MissingSymbolDeclarationError:a=>t.dieMessage(`[Parser](${d}): Missing symbol declaration for type: ${a.raw}`),UnsupportedTypeAliasDeclarationError:()=>t.dieMessage(`[Parser](${d}): Unsupported type alias declaration`),MultipleSymbolDeclarationsError:a=>t.dieMessage(`[Parser](${d}): Missing symbol declaration error for type: ${a.raw}`),MissingSymbolError:a=>t.dieMessage(`[Parser](${d}): Missing symbol error for type: ${a.raw}`),UnexportedDatabuilderError:a=>t.dieMessage(`[Parser](${d}): Unexported databuilder ${a.typeName}`),UnsupportedSyntaxKindError:a=>t.dieMessage(`[Parser](${d}): Unsupported syntax kind of id: ${a.kind} for type: ${a.raw}`),CannotBuildTypeReferenceMetadataError:a=>t.dieMessage(`[Parser](${d}): Cannot build type reference metadata with kind of id: ${a.kind} for type: ${a.raw}. Is it a root of databuilder?`),UnsupportedBuilderTypeError:a=>t.dieMessage(`[Parser](${d}): Unsupported builder type ${a.typeName}`)}))}}),dependencies:[Te.Default]}){},te=class extends V.TaggedError("UnsupportedSyntaxKindError"){},Me=class extends V.TaggedError("UnsupportedTypeAliasDeclarationError"){},Fe=class extends V.TaggedError("CannotBuildTypeReferenceMetadataError"){},Be=class extends V.TaggedError("ParserError"){},Ae=class extends V.TaggedError("UnexportedDatabuilderError"){},Re=class extends V.TaggedError("UnsupportedBuilderTypeError"){},Le=class extends V.TaggedError("MissingSymbolError"){},Ee=class extends V.TaggedError("MissingSymbolDeclarationError"){},Ne=class extends V.TaggedError("MultipleSymbolDeclarationsError"){};import*as rt from"effect/Chunk";import*as $ from"effect/Effect";import*as at from"effect/Function";var st=$.gen(function*(){let e=yield*X,o=yield*ie,c=yield*Q;yield*$.logInfo("[TSDatabuilders]: Generating builders for your project.");let f=yield*e.find;yield*$.logInfo(`[TSDatabuilders]: Found builders in ${f.length} file(s).`),yield*$.logDebug("[TSDatabuilders]: Attempting to generate builders metadata");let d=yield*$.all(rt.map(f,a=>o.generateBuildersMetadata(a)),{concurrency:"unbounded"}).pipe($.map(a=>a.flatMap(at.identity)));d.length!==0&&(yield*$.logDebug("[TSDatabuilders]: Attempting to create builders files"),yield*c.create(d),yield*$.logInfo(`[TSDatabuilders]: Created ${d.length} builder(s).`))});var ct="0.0.1-alpha.21";var $t=r.text("jsdoc-tag").pipe(r.withDescription(C.jsdocTag),r.withSchema(G.fields.jsdocTag),r.optional),vt=r.text("inline-default-jsdoc-tag").pipe(r.withDescription(C.inlineDefaultJsdocTag),r.withSchema(G.fields.inlineDefaultJsdocTag),r.optional),jt=r.text("with-nested-builders").pipe(r.withDescription(C.withNestedbuilders),r.withSchema(G.fields.withNestedBuilders),r.optional),Gt=r.text("output-dir").pipe(r.withAlias("o"),r.withDescription(C.outputDir),r.withSchema(G.fields.outputDir),r.optional),_t=r.text("include").pipe(r.withAlias("i"),r.withDescription(C.include),r.withSchema(G.fields.include),r.optional),Kt=r.text("file-case").pipe(r.withDescription(C.fileCase),r.withSchema(G.fields.fileCase),r.optional),Jt=r.text("file-suffix").pipe(r.withDescription(C.fileSuffix),r.withSchema(G.fields.fileSuffix),r.optional),Yt=r.text("builder-suffix").pipe(r.withDescription(C.builderSuffix),r.withSchema(G.fields.builderSuffix),r.optional),Wt=r.text("default-string").pipe(r.withDescription(C.defaultString),r.withSchema(G.fields.defaultString),r.optional),Vt=r.text("default-number").pipe(r.withDescription(C.defaultNumber),r.withSchema(G.fields.defaultNumber),r.optional),Zt=r.text("default-boolean").pipe(r.withDescription(C.defaultBoolean),r.withSchema(G.fields.defaultBoolean),r.optional),dt={jsdocTag:$t,outputDir:Gt,withNestedBuilders:jt,include:_t,fileSuffix:Jt,fileCase:Kt,builderSuffix:Yt,defaultString:Wt,defaultNumber:Vt,defaultBoolean:Zt,inlineDefaultJsdocTag:vt},zt=J.make("init",dt).pipe(J.withHandler(He)),qt=J.make("ts-databuilders",dt),lt=qt.pipe(J.withHandler(()=>st),J.withSubcommands([zt]),J.provide(e=>ne.mergeAll(X.Default,ie.Default,Q.Default).pipe(ne.provide(ne.effect(L,_e(e))))),J.run({name:"Typescript Databuilders generator",version:ct}));var Ht=mt.mergeAll(gt.minimumLogLevel(St.Info),R.Default,ft.layer);lt(process.argv).pipe(ut.provide(Ht),pt.runMain);
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@nemmtor/ts-databuilders",
|
|
4
|
+
"version": "0.0.1-alpha.21",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"private": false,
|
|
6
7
|
"description": "CLI tool that automatically generates builder classes from annotated TypeScript types.",
|
|
@@ -25,37 +26,60 @@
|
|
|
25
26
|
"files": [
|
|
26
27
|
"dist"
|
|
27
28
|
],
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build:node": "bun build src/main.ts --target node --outfile dist/main.js --production --packages external",
|
|
30
|
-
"start": "bun --console-depth 10 src/main.ts",
|
|
31
|
-
"format": "biome format",
|
|
32
|
-
"format:fix": "biome format --write",
|
|
33
|
-
"lint": "biome lint",
|
|
34
|
-
"lint:fix": "biome lint --write",
|
|
35
|
-
"check-actions": "pnpm exec biome check --formatter-enabled=false --linter-enabled=false",
|
|
36
|
-
"check-actions:fix": "pnpm exec biome check --formatter-enabled=false --linter-enabled=false --write",
|
|
37
|
-
"check-types": "tsc -b tsconfig.json",
|
|
38
|
-
"check-knip": "knip",
|
|
39
|
-
"check-dep": "depcruise --output-type err-long src"
|
|
40
|
-
},
|
|
41
29
|
"devDependencies": {
|
|
42
|
-
"@biomejs/biome": "^2.2
|
|
43
|
-
"@
|
|
30
|
+
"@biomejs/biome": "^2.3.2",
|
|
31
|
+
"@changesets/changelog-github": "^0.5.1",
|
|
32
|
+
"@changesets/cli": "^2.29.7",
|
|
33
|
+
"@commitlint/cli": "^20.1.0",
|
|
34
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
35
|
+
"@commitlint/prompt-cli": "^20.1.0",
|
|
36
|
+
"@effect/language-service": "^0.62.0",
|
|
37
|
+
"@effect/vitest": "^0.27.0",
|
|
44
38
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
45
|
-
"@types/
|
|
46
|
-
"
|
|
47
|
-
"
|
|
39
|
+
"@types/node": "^24.0.0",
|
|
40
|
+
"@vitest/coverage-v8": "4.0.16",
|
|
41
|
+
"dependency-cruiser": "^17.2.0",
|
|
42
|
+
"knip": "^5.66.4",
|
|
43
|
+
"lefthook": "^2.0.2",
|
|
44
|
+
"tsup": "^8.5.0",
|
|
45
|
+
"tsx": "^4.20.6",
|
|
46
|
+
"vitest": "^4.0.6"
|
|
48
47
|
},
|
|
49
48
|
"peerDependencies": {
|
|
50
49
|
"typescript": "^5.9.3"
|
|
51
50
|
},
|
|
52
51
|
"dependencies": {
|
|
53
|
-
"@effect/cli": "^0.
|
|
54
|
-
"@effect/platform": "^0.
|
|
55
|
-
"@effect/platform-node": "^0.
|
|
52
|
+
"@effect/cli": "^0.73.0",
|
|
53
|
+
"@effect/platform": "^0.94.0",
|
|
54
|
+
"@effect/platform-node": "^0.104.0",
|
|
56
55
|
"effect": "^3.18.4",
|
|
57
|
-
"glob": "^
|
|
56
|
+
"glob": "^13.0.0",
|
|
58
57
|
"ts-morph": "^27.0.2"
|
|
59
58
|
},
|
|
60
|
-
"
|
|
61
|
-
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=20.0.0"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:watch": "vitest",
|
|
66
|
+
"test:coverage": "vitest run --coverage",
|
|
67
|
+
"start": "tsx src/main.ts",
|
|
68
|
+
"format": "biome format",
|
|
69
|
+
"format:fix": "biome format --write",
|
|
70
|
+
"lint": "biome lint",
|
|
71
|
+
"lint:fix": "biome lint --write",
|
|
72
|
+
"check-actions": "pnpm exec biome check --formatter-enabled=false --linter-enabled=false",
|
|
73
|
+
"check-actions:fix": "pnpm exec biome check --formatter-enabled=false --linter-enabled=false --write",
|
|
74
|
+
"check-types": "tsc -b tsconfig.json",
|
|
75
|
+
"check-knip": "knip",
|
|
76
|
+
"check-dep": "depcruise --output-type err-long src",
|
|
77
|
+
"check-commits": "commitlint",
|
|
78
|
+
"generate:schema": "tsx scripts/generate-schema.ts",
|
|
79
|
+
"generate:version": "node scripts/generate-version.mjs",
|
|
80
|
+
"package:version": "changeset version && pnpm generate:version && git add --all",
|
|
81
|
+
"package:release": "pnpm build && changeset publish",
|
|
82
|
+
"postinstall": "pnpm lefthook install",
|
|
83
|
+
"commit": "commit"
|
|
84
|
+
}
|
|
85
|
+
}
|