hekireki 0.7.3 → 0.7.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 +24 -12
- package/dist/generator/effect/index.js +3 -3
- package/dist/generator/valibot/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,7 +257,7 @@ export const UserSchema = v.object({
|
|
|
257
257
|
name: v.pipe(v.string(), v.minLength(1), v.maxLength(50)),
|
|
258
258
|
})
|
|
259
259
|
|
|
260
|
-
export type User = v.
|
|
260
|
+
export type User = v.InferOutput<typeof UserSchema>
|
|
261
261
|
|
|
262
262
|
export const PostSchema = v.object({
|
|
263
263
|
/**
|
|
@@ -278,21 +278,21 @@ export const PostSchema = v.object({
|
|
|
278
278
|
userId: v.pipe(v.string(), v.uuid()),
|
|
279
279
|
})
|
|
280
280
|
|
|
281
|
-
export type Post = v.
|
|
281
|
+
export type Post = v.InferOutput<typeof PostSchema>
|
|
282
282
|
|
|
283
283
|
export const UserRelationsSchema = v.object({
|
|
284
284
|
...UserSchema.entries,
|
|
285
285
|
posts: v.array(PostSchema),
|
|
286
286
|
})
|
|
287
287
|
|
|
288
|
-
export type UserRelations = v.
|
|
288
|
+
export type UserRelations = v.InferOutput<typeof UserRelationsSchema>
|
|
289
289
|
|
|
290
290
|
export const PostRelationsSchema = v.object({
|
|
291
291
|
...PostSchema.entries,
|
|
292
292
|
user: UserSchema,
|
|
293
293
|
})
|
|
294
294
|
|
|
295
|
-
export type PostRelations = v.
|
|
295
|
+
export type PostRelations = v.InferOutput<typeof PostRelationsSchema>
|
|
296
296
|
```
|
|
297
297
|
|
|
298
298
|
### ArkType
|
|
@@ -329,26 +329,38 @@ export type Post = typeof PostSchema.infer
|
|
|
329
329
|
import { Schema } from 'effect'
|
|
330
330
|
|
|
331
331
|
export const UserSchema = Schema.Struct({
|
|
332
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Primary key
|
|
334
|
+
*/
|
|
333
335
|
id: Schema.UUID,
|
|
334
|
-
/**
|
|
336
|
+
/**
|
|
337
|
+
* Display name
|
|
338
|
+
*/
|
|
335
339
|
name: Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50)),
|
|
336
340
|
})
|
|
337
341
|
|
|
338
|
-
export type
|
|
342
|
+
export type UserEncoded = typeof UserSchema.Encoded
|
|
339
343
|
|
|
340
344
|
export const PostSchema = Schema.Struct({
|
|
341
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* Primary key
|
|
347
|
+
*/
|
|
342
348
|
id: Schema.UUID,
|
|
343
|
-
/**
|
|
349
|
+
/**
|
|
350
|
+
* Article title
|
|
351
|
+
*/
|
|
344
352
|
title: Schema.String.pipe(Schema.minLength(1), Schema.maxLength(100)),
|
|
345
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
* Body content (no length limit)
|
|
355
|
+
*/
|
|
346
356
|
content: Schema.String,
|
|
347
|
-
/**
|
|
357
|
+
/**
|
|
358
|
+
* Foreign key referencing User.id
|
|
359
|
+
*/
|
|
348
360
|
userId: Schema.UUID,
|
|
349
361
|
})
|
|
350
362
|
|
|
351
|
-
export type
|
|
363
|
+
export type PostEncoded = typeof PostSchema.Encoded
|
|
352
364
|
```
|
|
353
365
|
|
|
354
366
|
### TypeBox
|
|
@@ -7,14 +7,14 @@ import pkg from "@prisma/generator-helper";
|
|
|
7
7
|
|
|
8
8
|
//#region src/helper/effect.ts
|
|
9
9
|
function makeEffectInfer(modelName) {
|
|
10
|
-
return `export type ${modelName} =
|
|
10
|
+
return `export type ${modelName}Encoded = typeof ${modelName}Schema.Encoded`;
|
|
11
11
|
}
|
|
12
12
|
function makeEffectSchema(modelName, fields) {
|
|
13
13
|
return `export const ${modelName}Schema = Schema.Struct({\n${fields}\n})`;
|
|
14
14
|
}
|
|
15
15
|
function makeEffectProperties(fields, comment) {
|
|
16
16
|
return fields.map((field) => {
|
|
17
|
-
return `${comment && field.comment.length > 0 ?
|
|
17
|
+
return `${comment && field.comment.length > 0 ? ` /**\n${field.comment.map((c) => ` * ${c}`).join("\n")}\n */\n` : ""} ${field.fieldName}: ${field.validation ?? "Schema.Unknown"},`;
|
|
18
18
|
}).join("\n");
|
|
19
19
|
}
|
|
20
20
|
function makeEffectEnumExpression(values) {
|
|
@@ -37,7 +37,7 @@ function makeEffectSchemas(modelFields, comment) {
|
|
|
37
37
|
function makeEffectRelations(model, relProps, options) {
|
|
38
38
|
if (relProps.length === 0) return null;
|
|
39
39
|
const fields = `${`...${model.name}Schema.fields,`}${relProps.map((r) => `${r.key}:${r.isMany ? `Schema.Array(${r.targetModel}Schema)` : `${r.targetModel}Schema`},`).join("")}`;
|
|
40
|
-
const typeLine = options?.includeType ? `\n\nexport type ${model.name}
|
|
40
|
+
const typeLine = options?.includeType ? `\n\nexport type ${model.name}RelationsEncoded = typeof ${model.name}RelationsSchema.Encoded` : "";
|
|
41
41
|
return `export const ${model.name}RelationsSchema = Schema.Struct({${fields}})${typeLine}`;
|
|
42
42
|
}
|
|
43
43
|
function effect(models, type, comment, enums) {
|
|
@@ -7,7 +7,7 @@ import pkg from "@prisma/generator-helper";
|
|
|
7
7
|
|
|
8
8
|
//#region src/helper/valibot.ts
|
|
9
9
|
function makeValibotInfer(modelName) {
|
|
10
|
-
return `export type ${modelName} = v.
|
|
10
|
+
return `export type ${modelName} = v.InferOutput<typeof ${modelName}Schema>`;
|
|
11
11
|
}
|
|
12
12
|
function makeValibotSchema(modelName, fields) {
|
|
13
13
|
return `export const ${modelName}Schema = v.object({\n${fields}\n})`;
|
|
@@ -33,7 +33,7 @@ function makeValibotRelations(model, relProps, options) {
|
|
|
33
33
|
if (relProps.length === 0) return null;
|
|
34
34
|
const base = ` ...${model.name}Schema.entries,`;
|
|
35
35
|
const rels = relProps.map((r) => ` ${r.key}: ${r.isMany ? `v.array(${r.targetModel}Schema)` : `${r.targetModel}Schema`},`).join("\n");
|
|
36
|
-
const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = v.
|
|
36
|
+
const typeLine = options?.includeType ? `\n\nexport type ${model.name}Relations = v.InferOutput<typeof ${model.name}RelationsSchema>` : "";
|
|
37
37
|
return `export const ${model.name}RelationsSchema = v.object({\n${base}\n${rels}\n})${typeLine}`;
|
|
38
38
|
}
|
|
39
39
|
function valibot(models, type, comment, enums) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hekireki",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Hekireki is a tool that generates validation schemas for Zod, Valibot, ArkType, and Effect Schema, as well as ER diagrams and DBML, from Prisma schemas annotated with comments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ajv",
|