@danielfgray/pg-sourcerer 0.2.2 → 0.4.0

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.
Files changed (307) hide show
  1. package/bin/pgsourcerer +2 -0
  2. package/dist/__tests__/fixtures/index.d.ts +15 -0
  3. package/dist/__tests__/fixtures/index.d.ts.map +1 -0
  4. package/dist/__tests__/fixtures/index.js +19 -0
  5. package/dist/__tests__/fixtures/index.js.map +1 -0
  6. package/dist/__tests__/fixtures/introspection.json +40522 -0
  7. package/dist/cli.d.ts +0 -1
  8. package/dist/cli.js +7 -46
  9. package/dist/cli.js.map +1 -1
  10. package/dist/config.d.ts +38 -5
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +13 -2
  13. package/dist/config.js.map +1 -1
  14. package/dist/{lib/conjure.d.ts → conjure/index.d.ts} +62 -3
  15. package/dist/conjure/index.d.ts.map +1 -0
  16. package/dist/{lib/conjure.js → conjure/index.js} +124 -3
  17. package/dist/conjure/index.js.map +1 -0
  18. package/dist/conjure/signature.d.ts +85 -0
  19. package/dist/conjure/signature.d.ts.map +1 -0
  20. package/dist/conjure/signature.js +130 -0
  21. package/dist/conjure/signature.js.map +1 -0
  22. package/dist/conjure/types.d.ts +97 -0
  23. package/dist/conjure/types.d.ts.map +1 -0
  24. package/dist/conjure/types.js +206 -0
  25. package/dist/conjure/types.js.map +1 -0
  26. package/dist/errors.d.ts +114 -139
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +82 -36
  29. package/dist/errors.js.map +1 -1
  30. package/dist/generate.d.ts +45 -46
  31. package/dist/generate.d.ts.map +1 -1
  32. package/dist/generate.js +86 -59
  33. package/dist/generate.js.map +1 -1
  34. package/dist/hex/builder.d.ts +12 -0
  35. package/dist/hex/builder.d.ts.map +1 -0
  36. package/dist/hex/builder.js +64 -0
  37. package/dist/hex/builder.js.map +1 -0
  38. package/dist/hex/ddl.d.ts +53 -0
  39. package/dist/hex/ddl.d.ts.map +1 -0
  40. package/dist/hex/ddl.js +306 -0
  41. package/dist/hex/ddl.js.map +1 -0
  42. package/dist/hex/index.d.ts +105 -0
  43. package/dist/hex/index.d.ts.map +1 -0
  44. package/dist/hex/index.js +81 -0
  45. package/dist/hex/index.js.map +1 -0
  46. package/dist/hex/primitives.d.ts +23 -0
  47. package/dist/hex/primitives.d.ts.map +1 -0
  48. package/dist/hex/primitives.js +38 -0
  49. package/dist/hex/primitives.js.map +1 -0
  50. package/dist/hex/query.d.ts +116 -0
  51. package/dist/hex/query.d.ts.map +1 -0
  52. package/dist/hex/query.js +219 -0
  53. package/dist/hex/query.js.map +1 -0
  54. package/dist/hex/types.d.ts +287 -0
  55. package/dist/hex/types.d.ts.map +1 -0
  56. package/dist/hex/types.js +431 -0
  57. package/dist/hex/types.js.map +1 -0
  58. package/dist/index.d.ts +17 -25
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +33 -44
  61. package/dist/index.js.map +1 -1
  62. package/dist/init.d.ts.map +1 -1
  63. package/dist/init.js +76 -140
  64. package/dist/init.js.map +1 -1
  65. package/dist/ir/extensions/queries.d.ts +6 -6
  66. package/dist/ir/extensions/queries.d.ts.map +1 -1
  67. package/dist/ir/extensions/queries.js +6 -4
  68. package/dist/ir/extensions/queries.js.map +1 -1
  69. package/dist/ir/extensions/schema-builder.d.ts.map +1 -1
  70. package/dist/ir/extensions/schema-builder.js.map +1 -1
  71. package/dist/ir/index.d.ts.map +1 -1
  72. package/dist/ir/index.js.map +1 -1
  73. package/dist/ir/relation-graph.d.ts.map +1 -1
  74. package/dist/ir/relation-graph.js +8 -8
  75. package/dist/ir/relation-graph.js.map +1 -1
  76. package/dist/ir/semantic-ir.d.ts +38 -0
  77. package/dist/ir/semantic-ir.d.ts.map +1 -1
  78. package/dist/ir/semantic-ir.js +50 -2
  79. package/dist/ir/semantic-ir.js.map +1 -1
  80. package/dist/ir/smart-tags.d.ts.map +1 -1
  81. package/dist/ir/smart-tags.js.map +1 -1
  82. package/dist/lib/field-utils.d.ts.map +1 -1
  83. package/dist/lib/field-utils.js +7 -7
  84. package/dist/lib/field-utils.js.map +1 -1
  85. package/dist/lib/join-graph.d.ts +95 -0
  86. package/dist/lib/join-graph.d.ts.map +1 -0
  87. package/dist/lib/join-graph.js +305 -0
  88. package/dist/lib/join-graph.js.map +1 -0
  89. package/dist/lib/picker.d.ts +60 -0
  90. package/dist/lib/picker.d.ts.map +1 -0
  91. package/dist/lib/picker.js +325 -0
  92. package/dist/lib/picker.js.map +1 -0
  93. package/dist/plugins/arktype.d.ts +20 -24
  94. package/dist/plugins/arktype.d.ts.map +1 -1
  95. package/dist/plugins/arktype.js +462 -386
  96. package/dist/plugins/arktype.js.map +1 -1
  97. package/dist/plugins/effect/http.d.ts +7 -0
  98. package/dist/plugins/effect/http.d.ts.map +1 -0
  99. package/dist/plugins/effect/http.js +460 -0
  100. package/dist/plugins/effect/http.js.map +1 -0
  101. package/dist/plugins/effect/index.d.ts +22 -0
  102. package/dist/plugins/effect/index.d.ts.map +1 -0
  103. package/dist/plugins/effect/index.js +65 -0
  104. package/dist/plugins/effect/index.js.map +1 -0
  105. package/dist/plugins/effect/models.d.ts +6 -0
  106. package/dist/plugins/effect/models.d.ts.map +1 -0
  107. package/dist/plugins/effect/models.js +116 -0
  108. package/dist/plugins/effect/models.js.map +1 -0
  109. package/dist/plugins/effect/repos.d.ts +21 -0
  110. package/dist/plugins/effect/repos.d.ts.map +1 -0
  111. package/dist/plugins/effect/repos.js +131 -0
  112. package/dist/plugins/effect/repos.js.map +1 -0
  113. package/dist/plugins/effect/schemas.d.ts +7 -0
  114. package/dist/plugins/effect/schemas.d.ts.map +1 -0
  115. package/dist/plugins/effect/schemas.js +75 -0
  116. package/dist/plugins/effect/schemas.js.map +1 -0
  117. package/dist/plugins/effect/shared.d.ts +116 -0
  118. package/dist/plugins/effect/shared.d.ts.map +1 -0
  119. package/dist/plugins/effect/shared.js +164 -0
  120. package/dist/plugins/effect/shared.js.map +1 -0
  121. package/dist/plugins/http-elysia.d.ts +20 -27
  122. package/dist/plugins/http-elysia.d.ts.map +1 -1
  123. package/dist/plugins/http-elysia.js +350 -475
  124. package/dist/plugins/http-elysia.js.map +1 -1
  125. package/dist/plugins/http-express.d.ts +20 -31
  126. package/dist/plugins/http-express.d.ts.map +1 -1
  127. package/dist/plugins/http-express.js +281 -268
  128. package/dist/plugins/http-express.js.map +1 -1
  129. package/dist/plugins/http-hono.d.ts +17 -33
  130. package/dist/plugins/http-hono.d.ts.map +1 -1
  131. package/dist/plugins/http-hono.js +317 -341
  132. package/dist/plugins/http-hono.js.map +1 -1
  133. package/dist/plugins/http-orpc.d.ts +34 -33
  134. package/dist/plugins/http-orpc.d.ts.map +1 -1
  135. package/dist/plugins/http-orpc.js +345 -257
  136. package/dist/plugins/http-orpc.js.map +1 -1
  137. package/dist/plugins/http-trpc.d.ts +33 -35
  138. package/dist/plugins/http-trpc.d.ts.map +1 -1
  139. package/dist/plugins/http-trpc.js +337 -241
  140. package/dist/plugins/http-trpc.js.map +1 -1
  141. package/dist/plugins/kysely.d.ts +54 -59
  142. package/dist/plugins/kysely.d.ts.map +1 -1
  143. package/dist/plugins/kysely.js +826 -687
  144. package/dist/plugins/kysely.js.map +1 -1
  145. package/dist/plugins/sql-queries.d.ts +38 -44
  146. package/dist/plugins/sql-queries.d.ts.map +1 -1
  147. package/dist/plugins/sql-queries.js +497 -897
  148. package/dist/plugins/sql-queries.js.map +1 -1
  149. package/dist/plugins/types.d.ts +12 -20
  150. package/dist/plugins/types.d.ts.map +1 -1
  151. package/dist/plugins/types.js +84 -227
  152. package/dist/plugins/types.js.map +1 -1
  153. package/dist/plugins/valibot.d.ts +7 -44
  154. package/dist/plugins/valibot.d.ts.map +1 -1
  155. package/dist/plugins/valibot.js +376 -382
  156. package/dist/plugins/valibot.js.map +1 -1
  157. package/dist/plugins/zod.d.ts +20 -24
  158. package/dist/plugins/zod.d.ts.map +1 -1
  159. package/dist/plugins/zod.js +370 -367
  160. package/dist/plugins/zod.js.map +1 -1
  161. package/dist/runtime/emit.d.ts +64 -0
  162. package/dist/runtime/emit.d.ts.map +1 -0
  163. package/dist/runtime/emit.js +445 -0
  164. package/dist/runtime/emit.js.map +1 -0
  165. package/dist/runtime/errors.d.ts +36 -0
  166. package/dist/runtime/errors.d.ts.map +1 -0
  167. package/dist/runtime/errors.js +29 -0
  168. package/dist/runtime/errors.js.map +1 -0
  169. package/dist/runtime/file-assignment.d.ts +161 -0
  170. package/dist/runtime/file-assignment.d.ts.map +1 -0
  171. package/dist/runtime/file-assignment.js +195 -0
  172. package/dist/runtime/file-assignment.js.map +1 -0
  173. package/dist/runtime/orchestrator.d.ts +62 -0
  174. package/dist/runtime/orchestrator.d.ts.map +1 -0
  175. package/dist/runtime/orchestrator.js +99 -0
  176. package/dist/runtime/orchestrator.js.map +1 -0
  177. package/dist/runtime/registry.d.ts +268 -0
  178. package/dist/runtime/registry.d.ts.map +1 -0
  179. package/dist/runtime/registry.js +436 -0
  180. package/dist/runtime/registry.js.map +1 -0
  181. package/dist/runtime/types.d.ts +182 -0
  182. package/dist/runtime/types.d.ts.map +1 -0
  183. package/dist/runtime/types.js +2 -0
  184. package/dist/runtime/types.js.map +1 -0
  185. package/dist/runtime/validation.d.ts +41 -0
  186. package/dist/runtime/validation.d.ts.map +1 -0
  187. package/dist/runtime/validation.js +70 -0
  188. package/dist/runtime/validation.js.map +1 -0
  189. package/dist/services/config-loader.d.ts.map +1 -1
  190. package/dist/services/config-loader.js +15 -6
  191. package/dist/services/config-loader.js.map +1 -1
  192. package/dist/services/config.d.ts +55 -25
  193. package/dist/services/config.d.ts.map +1 -1
  194. package/dist/services/config.js +60 -34
  195. package/dist/services/config.js.map +1 -1
  196. package/dist/services/file-writer.d.ts +3 -3
  197. package/dist/services/file-writer.d.ts.map +1 -1
  198. package/dist/services/file-writer.js +6 -8
  199. package/dist/services/file-writer.js.map +1 -1
  200. package/dist/services/inflection.d.ts +126 -27
  201. package/dist/services/inflection.d.ts.map +1 -1
  202. package/dist/services/inflection.js +300 -72
  203. package/dist/services/inflection.js.map +1 -1
  204. package/dist/services/introspection.d.ts.map +1 -1
  205. package/dist/services/introspection.js +6 -6
  206. package/dist/services/introspection.js.map +1 -1
  207. package/dist/services/ir-builder.d.ts.map +1 -1
  208. package/dist/services/ir-builder.js +73 -77
  209. package/dist/services/ir-builder.js.map +1 -1
  210. package/dist/services/ir.d.ts.map +1 -1
  211. package/dist/services/ir.js.map +1 -1
  212. package/dist/services/pg-types.d.ts.map +1 -1
  213. package/dist/services/pg-types.js +3 -3
  214. package/dist/services/pg-types.js.map +1 -1
  215. package/dist/services/smart-tags-parser.d.ts.map +1 -1
  216. package/dist/services/smart-tags-parser.js +4 -4
  217. package/dist/services/smart-tags-parser.js.map +1 -1
  218. package/dist/services/type-hints.d.ts.map +1 -1
  219. package/dist/services/type-hints.js +1 -1
  220. package/dist/services/type-hints.js.map +1 -1
  221. package/dist/services/user-module-parser.d.ts +46 -0
  222. package/dist/services/user-module-parser.d.ts.map +1 -0
  223. package/dist/services/user-module-parser.js +181 -0
  224. package/dist/services/user-module-parser.js.map +1 -0
  225. package/dist/shared/converters.d.ts +60 -0
  226. package/dist/shared/converters.d.ts.map +1 -0
  227. package/dist/shared/converters.js +168 -0
  228. package/dist/shared/converters.js.map +1 -0
  229. package/dist/shared/query-types.d.ts +95 -0
  230. package/dist/shared/query-types.d.ts.map +1 -0
  231. package/dist/shared/query-types.js +9 -0
  232. package/dist/shared/query-types.js.map +1 -0
  233. package/dist/testing.d.ts +125 -37
  234. package/dist/testing.d.ts.map +1 -1
  235. package/dist/testing.js +134 -42
  236. package/dist/testing.js.map +1 -1
  237. package/dist/user-module.d.ts +86 -0
  238. package/dist/user-module.d.ts.map +1 -0
  239. package/dist/user-module.js +55 -0
  240. package/dist/user-module.js.map +1 -0
  241. package/package.json +10 -6
  242. package/dist/lib/conjure.d.ts.map +0 -1
  243. package/dist/lib/conjure.js.map +0 -1
  244. package/dist/lib/hex.d.ts +0 -119
  245. package/dist/lib/hex.d.ts.map +0 -1
  246. package/dist/lib/hex.js +0 -188
  247. package/dist/lib/hex.js.map +0 -1
  248. package/dist/plugins/effect.d.ts +0 -53
  249. package/dist/plugins/effect.d.ts.map +0 -1
  250. package/dist/plugins/effect.js +0 -1074
  251. package/dist/plugins/effect.js.map +0 -1
  252. package/dist/plugins/kysely/queries.d.ts +0 -92
  253. package/dist/plugins/kysely/queries.d.ts.map +0 -1
  254. package/dist/plugins/kysely/queries.js +0 -1169
  255. package/dist/plugins/kysely/queries.js.map +0 -1
  256. package/dist/plugins/kysely/shared.d.ts +0 -59
  257. package/dist/plugins/kysely/shared.d.ts.map +0 -1
  258. package/dist/plugins/kysely/shared.js +0 -247
  259. package/dist/plugins/kysely/shared.js.map +0 -1
  260. package/dist/plugins/kysely/types.d.ts +0 -22
  261. package/dist/plugins/kysely/types.d.ts.map +0 -1
  262. package/dist/plugins/kysely/types.js +0 -428
  263. package/dist/plugins/kysely/types.js.map +0 -1
  264. package/dist/services/artifact-store.d.ts +0 -65
  265. package/dist/services/artifact-store.d.ts.map +0 -1
  266. package/dist/services/artifact-store.js +0 -57
  267. package/dist/services/artifact-store.js.map +0 -1
  268. package/dist/services/core-providers.d.ts +0 -15
  269. package/dist/services/core-providers.d.ts.map +0 -1
  270. package/dist/services/core-providers.js +0 -23
  271. package/dist/services/core-providers.js.map +0 -1
  272. package/dist/services/emissions.d.ts +0 -103
  273. package/dist/services/emissions.d.ts.map +0 -1
  274. package/dist/services/emissions.js +0 -241
  275. package/dist/services/emissions.js.map +0 -1
  276. package/dist/services/execution.d.ts +0 -35
  277. package/dist/services/execution.d.ts.map +0 -1
  278. package/dist/services/execution.js +0 -86
  279. package/dist/services/execution.js.map +0 -1
  280. package/dist/services/file-builder.d.ts +0 -85
  281. package/dist/services/file-builder.d.ts.map +0 -1
  282. package/dist/services/file-builder.js +0 -112
  283. package/dist/services/file-builder.js.map +0 -1
  284. package/dist/services/plugin-meta.d.ts +0 -33
  285. package/dist/services/plugin-meta.d.ts.map +0 -1
  286. package/dist/services/plugin-meta.js +0 -24
  287. package/dist/services/plugin-meta.js.map +0 -1
  288. package/dist/services/plugin-runner.d.ts +0 -42
  289. package/dist/services/plugin-runner.d.ts.map +0 -1
  290. package/dist/services/plugin-runner.js +0 -84
  291. package/dist/services/plugin-runner.js.map +0 -1
  292. package/dist/services/plugin.d.ts +0 -421
  293. package/dist/services/plugin.d.ts.map +0 -1
  294. package/dist/services/plugin.js +0 -197
  295. package/dist/services/plugin.js.map +0 -1
  296. package/dist/services/resolution.d.ts +0 -38
  297. package/dist/services/resolution.d.ts.map +0 -1
  298. package/dist/services/resolution.js +0 -242
  299. package/dist/services/resolution.js.map +0 -1
  300. package/dist/services/service-registry.d.ts +0 -74
  301. package/dist/services/service-registry.d.ts.map +0 -1
  302. package/dist/services/service-registry.js +0 -61
  303. package/dist/services/service-registry.js.map +0 -1
  304. package/dist/services/symbols.d.ts +0 -144
  305. package/dist/services/symbols.d.ts.map +0 -1
  306. package/dist/services/symbols.js +0 -144
  307. package/dist/services/symbols.js.map +0 -1
@@ -1,422 +1,416 @@
1
1
  /**
2
- * Valibot Plugin - Generate Valibot schemas for entities
2
+ * Valibot Plugin - Generates Valibot schemas for entities
3
3
  *
4
4
  * Generates Valibot schemas for Row, Insert, Update, and Patch shapes,
5
- * with inferred TypeScript types.
5
+ * with optional inferred TypeScript types.
6
+ *
7
+ * Capabilities provided:
8
+ * - `schema:valibot:EntityName` for each table entity (Row schema)
9
+ * - `schema:valibot:EntityName:insert` for Insert shape
10
+ * - `schema:valibot:EntityName:update` for Update shape
11
+ * - `schema:valibot:EnumName` for enum entities
6
12
  */
7
- import { Array as Arr, Option, pipe, Schema as S } from "effect";
8
- import { definePlugin } from "../services/plugin.js";
9
- import { findEnumByPgName, TsType } from "../services/pg-types.js";
10
- import { getTableEntities, getEnumEntities, getCompositeEntities } from "../ir/semantic-ir.js";
11
- import { conjure } from "../lib/conjure.js";
12
- import { isUuidType, isDateType, isEnumType, getPgTypeName, resolveFieldType, } from "../lib/field-utils.js";
13
- import { SCHEMA_BUILDER_KIND, } from "../ir/extensions/schema-builder.js";
14
- const { ts, exp, obj, b } = conjure;
15
- // ============================================================================
16
- // Configuration
17
- // ============================================================================
18
- const ValibotConfigSchema = S.Struct({
19
- /** Output directory relative to main outputDir */
20
- outputDir: S.optionalWith(S.String, { default: () => "valibot" }),
21
- /** Export inferred types alongside schemas */
13
+ import { Effect, Schema as S } from "effect";
14
+ import { normalizeFileNaming } from "../runtime/file-assignment.js";
15
+ import { SymbolRegistry } from "../runtime/registry.js";
16
+ import { IR } from "../services/ir.js";
17
+ import { isTableEntity, isEnumEntity, } from "../ir/semantic-ir.js";
18
+ import { conjure, cast } from "../conjure/index.js";
19
+ const b = conjure.b;
20
+ const ValibotSchemaConfig = S.Struct({
22
21
  exportTypes: S.optionalWith(S.Boolean, { default: () => true }),
23
- /** How to represent enum values: 'strings' uses v.picklist([...]), 'enum' uses v.enum(TsEnum) */
24
- enumStyle: S.optionalWith(S.Union(S.Literal("strings"), S.Literal("enum")), {
25
- default: () => "strings",
26
- }),
27
- /** Where to define enum types: 'inline' embeds at usage, 'separate' generates enum files */
28
- typeReferences: S.optionalWith(S.Union(S.Literal("inline"), S.Literal("separate")), {
29
- default: () => "separate",
30
- }),
31
22
  });
32
- // ============================================================================
33
- // Valibot Schema Builders (pure functions)
34
- // ============================================================================
35
- // ============================================================================
36
- // Valibot Schema Builders (pure functions)
37
- // ============================================================================
38
- /**
39
- * Build v.<method>() call
40
- */
41
- const buildValibotCall = (method, args = []) => conjure
42
- .id("v")
43
- .method(method, [...args])
44
- .build();
45
- /**
46
- * Build v.picklist([...values])
47
- */
48
- const buildValibotPicklist = (values) => buildValibotCall("picklist", [conjure.arr(...values.map(v => conjure.str(v))).build()]);
49
- /**
50
- * Build v.array(<inner>)
51
- */
52
- const buildValibotArray = (inner) => buildValibotCall("array", [inner]);
53
- /**
54
- * Wrap expression with v.nullable(...)
55
- */
56
- const wrapNullable = (expr) => buildValibotCall("nullable", [expr]);
57
- /**
58
- * Wrap expression with v.optional(...)
59
- */
60
- const wrapOptional = (expr) => buildValibotCall("optional", [expr]);
61
- /**
62
- * Map TypeScript type to Valibot method name
63
- */
64
- const tsTypeToValibotMethod = (tsType) => {
65
- switch (tsType) {
66
- case TsType.String:
67
- return "string";
68
- case TsType.Number:
69
- return "number";
70
- case TsType.Boolean:
71
- return "boolean";
72
- case TsType.BigInt:
73
- return "bigint";
74
- case TsType.Date:
75
- return "date";
76
- case TsType.Buffer:
77
- case TsType.Unknown:
78
- default:
79
- return "unknown";
23
+ const PG_STRING_TYPES = new Set([
24
+ "uuid",
25
+ "text",
26
+ "varchar",
27
+ "char",
28
+ "character",
29
+ "name",
30
+ "bpchar",
31
+ "citext",
32
+ ]);
33
+ const PG_NUMBER_TYPES = new Set([
34
+ "int2",
35
+ "int4",
36
+ "int8",
37
+ "integer",
38
+ "smallint",
39
+ "bigint",
40
+ "numeric",
41
+ "decimal",
42
+ "real",
43
+ "float4",
44
+ "float8",
45
+ "double",
46
+ ]);
47
+ const PG_BOOLEAN_TYPES = new Set(["bool", "boolean"]);
48
+ const PG_DATE_TYPES = new Set(["timestamp", "timestamptz", "date", "time", "timetz"]);
49
+ const PG_JSON_TYPES = new Set(["json", "jsonb"]);
50
+ function fieldToValibotMapping(field, enums) {
51
+ const pgType = field.pgAttribute.getType();
52
+ if (!pgType) {
53
+ return { kind: "schema", schema: conjure.id("v").method("unknown").build() };
80
54
  }
81
- };
82
- /**
83
- * Apply nullable/optional/array modifiers to a base schema
84
- * Order matters: array wraps first, then nullable, then optional
85
- */
86
- const applyFieldModifiers = (schema, field) => {
87
- let result = schema;
88
- // Array wrapping first
89
- if (field.isArray) {
90
- result = buildValibotArray(result);
55
+ let typeName;
56
+ let typeInfo;
57
+ if (pgType.typcategory === "A") {
58
+ typeName = field.elementTypeName ?? "unknown";
59
+ typeInfo = pgType;
91
60
  }
92
- // Nullable wrapping
93
- if (field.nullable) {
94
- result = wrapNullable(result);
61
+ else if (pgType.typtype === "d" && field.domainBaseType) {
62
+ typeName = field.domainBaseType.typeName;
63
+ typeInfo = { typcategory: field.domainBaseType.category };
95
64
  }
96
- // Optional wrapping
97
- if (field.optional) {
98
- result = wrapOptional(result);
65
+ else {
66
+ typeName = pgType.typname;
67
+ typeInfo = pgType;
99
68
  }
100
- return result;
101
- };
102
- /**
103
- * Resolve a field to its Valibot schema expression
104
- */
105
- const resolveFieldValibotSchema = (field, ctx) => {
106
- const resolved = resolveFieldType(field, ctx.enums, ctx.extensions);
107
- // Enum handling
108
- if (resolved.enumDef) {
109
- let enumSchema;
110
- if (ctx.typeReferences === "separate") {
111
- // Reference by name - the enum schema is imported
112
- enumSchema = conjure.id(resolved.enumDef.name).build();
113
- }
114
- else if (ctx.enumStyle === "enum") {
115
- // Inline native enum: v.enum(EnumName)
116
- // Note: This requires the TS enum to be generated separately
117
- enumSchema = buildValibotCall("enum", [conjure.id(resolved.enumDef.name).build()]);
118
- }
119
- else {
120
- // Inline strings: v.picklist(['a', 'b', 'c'])
121
- enumSchema = buildValibotPicklist(resolved.enumDef.values);
122
- }
123
- return applyFieldModifiers(enumSchema, field);
69
+ const baseResult = baseTypeToValibotMapping(typeName, typeInfo, enums);
70
+ if (baseResult.kind === "enumRef") {
71
+ return baseResult;
124
72
  }
125
- // UUID v.pipe(v.string(), v.uuid())
126
- if (isUuidType(field)) {
127
- const uuidSchema = buildValibotCall("pipe", [
128
- buildValibotCall("string"),
129
- buildValibotCall("uuid"),
130
- ]);
131
- return applyFieldModifiers(uuidSchema, field);
73
+ let schema = baseResult.schema;
74
+ if (field.isArray) {
75
+ schema = conjure.id("v").method("array", [schema]).build();
132
76
  }
133
- // Date/timestamp v.date()
134
- if (isDateType(field)) {
135
- return applyFieldModifiers(buildValibotCall("date"), field);
77
+ const methods = [];
78
+ if (field.nullable)
79
+ methods.push("nullable");
80
+ if (field.optional)
81
+ methods.push("optional");
82
+ for (const method of methods) {
83
+ schema = conjure.id("v").method(method, [schema]).build();
136
84
  }
137
- // Standard type mapping
138
- return applyFieldModifiers(buildValibotCall(tsTypeToValibotMethod(resolved.tsType)), field);
139
- };
140
- // ============================================================================
141
- // Shape → Statement Generation
142
- // ============================================================================
143
- /**
144
- * Build v.object({...}) expression from shape fields
145
- */
146
- const buildShapeValibotObject = (shape, ctx) => {
147
- const objBuilder = shape.fields.reduce((builder, field) => builder.prop(field.name, resolveFieldValibotSchema(field, ctx)), obj());
148
- return buildValibotCall("object", [objBuilder.build()]);
149
- };
150
- /**
151
- * Generate schema const + optional inferred type for a shape
152
- */
153
- const generateShapeStatements = (shape, entityName, shapeKind, ctx, exportTypes) => {
154
- const schemaSymbolCtx = { capability: "schemas", entity: entityName, shape: shapeKind };
155
- const schemaExpr = buildShapeValibotObject(shape, ctx);
156
- const schemaStatement = exp.const(shape.name, schemaSymbolCtx, schemaExpr);
157
- if (!exportTypes) {
158
- return [schemaStatement];
85
+ return { kind: "schema", schema };
86
+ }
87
+ function baseTypeToValibotMapping(typeName, pgType, enums) {
88
+ const normalized = typeName.toLowerCase();
89
+ if (PG_STRING_TYPES.has(normalized)) {
90
+ if (normalized === "uuid") {
91
+ const uuidSchema = conjure
92
+ .id("v")
93
+ .method("pipe", [
94
+ conjure.id("v").method("string").build(),
95
+ conjure.id("v").method("uuid").build(),
96
+ ])
97
+ .build();
98
+ return { kind: "schema", schema: uuidSchema };
99
+ }
100
+ return { kind: "schema", schema: conjure.id("v").method("string").build() };
159
101
  }
160
- // Generate: export type ShapeName = v.InferOutput<typeof ShapeName>
161
- // Register under "types" capability so other plugins can import
162
- const typeSymbolCtx = { capability: "types", entity: entityName, shape: shapeKind };
163
- const inferType = ts.qualifiedRef("v", "InferOutput", [ts.typeof(shape.name)]);
164
- const typeStatement = exp.type(shape.name, typeSymbolCtx, inferType);
165
- return [schemaStatement, typeStatement];
166
- };
167
- /**
168
- * Collect all defined shapes from an entity as [kind, shape] pairs
169
- */
170
- const collectShapes = (entity) => [
171
- ["row", entity.shapes.row],
172
- ["insert", entity.shapes.insert],
173
- ["update", entity.shapes.update],
174
- ].filter((entry) => entry[1] != null);
175
- /**
176
- * Generate all statements for an entity's shapes
177
- */
178
- const generateEntityStatements = (entity, ctx, exportTypes) => collectShapes(entity).flatMap(([kind, shape]) => generateShapeStatements(shape, entity.name, kind, ctx, exportTypes));
179
- // ============================================================================
180
- // Composite Type Generation
181
- // ============================================================================
182
- /**
183
- * Build v.object({...}) expression from composite fields
184
- */
185
- const buildCompositeValibotObject = (composite, ctx) => {
186
- const objBuilder = composite.fields.reduce((builder, field) => builder.prop(field.name, resolveFieldValibotSchema(field, ctx)), obj());
187
- return buildValibotCall("object", [objBuilder.build()]);
188
- };
189
- /**
190
- * Generate schema const + optional inferred type for a composite type
191
- */
192
- const generateCompositeStatements = (composite, ctx, exportTypes) => {
193
- const schemaSymbolCtx = { capability: "schemas", entity: composite.name };
194
- const schemaExpr = buildCompositeValibotObject(composite, ctx);
195
- const schemaStatement = exp.const(composite.name, schemaSymbolCtx, schemaExpr);
196
- if (!exportTypes) {
197
- return [schemaStatement];
102
+ if (PG_NUMBER_TYPES.has(normalized)) {
103
+ return { kind: "schema", schema: conjure.id("v").method("number").build() };
198
104
  }
199
- // Generate: export type CompositeName = v.InferOutput<typeof CompositeName>
200
- // Register under "types" capability so other plugins can import
201
- const typeSymbolCtx = { capability: "types", entity: composite.name };
202
- const inferType = ts.qualifiedRef("v", "InferOutput", [ts.typeof(composite.name)]);
203
- const typeStatement = exp.type(composite.name, typeSymbolCtx, inferType);
204
- return [schemaStatement, typeStatement];
205
- };
206
- // ============================================================================
207
- // Enum Generation
208
- // ============================================================================
209
- /**
210
- * Generate enum schema statement: export const EnumName = v.picklist(['a', 'b', ...])
211
- * or for native enums: export enum EnumName { A = 'a', ... } + schema
212
- */
213
- const generateEnumStatement = (enumEntity, enumStyle, exportTypes) => {
214
- const schemaSymbolCtx = { capability: "schemas", entity: enumEntity.name };
215
- if (enumStyle === "enum") {
216
- // Generate: export enum EnumName { A = 'a', B = 'b', ... }
217
- // Then: export const EnumNameSchema = v.enum(EnumName)
218
- const enumStatement = exp.tsEnum(enumEntity.name, { capability: "types", entity: enumEntity.name }, enumEntity.values);
219
- const schemaName = `${enumEntity.name}Schema`;
220
- const schemaExpr = buildValibotCall("enum", [conjure.id(enumEntity.name).build()]);
221
- const schemaStatement = exp.const(schemaName, schemaSymbolCtx, schemaExpr);
222
- return [enumStatement, schemaStatement];
105
+ if (PG_BOOLEAN_TYPES.has(normalized)) {
106
+ return { kind: "schema", schema: conjure.id("v").method("boolean").build() };
223
107
  }
224
- // strings style: export const EnumName = v.picklist(['a', 'b', ...])
225
- const schemaExpr = buildValibotPicklist(enumEntity.values);
226
- const schemaStatement = exp.const(enumEntity.name, schemaSymbolCtx, schemaExpr);
227
- if (!exportTypes) {
228
- return [schemaStatement];
108
+ if (PG_DATE_TYPES.has(normalized)) {
109
+ return { kind: "schema", schema: conjure.id("v").method("date").build() };
229
110
  }
230
- // Generate: export type EnumName = v.InferOutput<typeof EnumName>
231
- // Register under "types" capability so other plugins can import
232
- const typeSymbolCtx = { capability: "types", entity: enumEntity.name };
233
- const inferType = ts.qualifiedRef("v", "InferOutput", [ts.typeof(enumEntity.name)]);
234
- const typeStatement = exp.type(enumEntity.name, typeSymbolCtx, inferType);
235
- return [schemaStatement, typeStatement];
236
- };
237
- /** Collect enum names used by fields */
238
- const collectUsedEnums = (fields, enums) => {
239
- const enumNames = fields.filter(isEnumType).flatMap(field => {
240
- const pgTypeName = getPgTypeName(field);
241
- if (!pgTypeName)
242
- return [];
243
- return pipe(findEnumByPgName(enums, pgTypeName), Option.map(e => e.name), Option.toArray);
111
+ if (PG_JSON_TYPES.has(normalized)) {
112
+ return { kind: "schema", schema: conjure.id("v").method("unknown").build() };
113
+ }
114
+ if (pgType.typtype === "e" || pgType.typcategory === "E") {
115
+ const enumEntity = enums.find(e => e.pgType.typname === typeName);
116
+ if (enumEntity) {
117
+ return { kind: "enumRef", enumRef: enumEntity.name };
118
+ }
119
+ return { kind: "schema", schema: conjure.id("v").method("unknown").build() };
120
+ }
121
+ return { kind: "schema", schema: conjure.id("v").method("unknown").build() };
122
+ }
123
+ function shapeToValibotObject(shape, enums, registry) {
124
+ const properties = shape.fields.map(field => {
125
+ const mapping = fieldToValibotMapping(field, enums);
126
+ let value;
127
+ if (mapping.kind === "enumRef") {
128
+ const enumHandle = registry.import(`schema:valibot:${mapping.enumRef}`);
129
+ value = enumHandle.ref();
130
+ if (field.isArray) {
131
+ value = conjure.id("v").method("array", [value]).build();
132
+ }
133
+ if (field.nullable) {
134
+ value = conjure.id("v").method("nullable", [value]).build();
135
+ }
136
+ if (field.optional) {
137
+ value = conjure.id("v").method("optional", [value]).build();
138
+ }
139
+ }
140
+ else {
141
+ value = mapping.schema;
142
+ }
143
+ return b.objectProperty(b.identifier(field.name), cast.toExpr(value));
244
144
  });
245
- return new Set(enumNames);
145
+ const objExpr = b.objectExpression(properties);
146
+ const vObject = b.callExpression(b.memberExpression(b.identifier("v"), b.identifier("object")), [
147
+ objExpr,
148
+ ]);
149
+ return vObject;
150
+ }
151
+ function createValibotConsumeCallback(schemaName) {
152
+ return (input) => {
153
+ return conjure
154
+ .id("v")
155
+ .method("parse", [conjure.id(schemaName).build(), cast.toExpr(input)])
156
+ .build();
157
+ };
158
+ }
159
+ const valibotSchemaBuilder = {
160
+ build(request) {
161
+ if (request.params.length === 0) {
162
+ return undefined;
163
+ }
164
+ let objBuilder = conjure.obj();
165
+ for (const param of request.params) {
166
+ const valibotType = paramToValibotType(param);
167
+ objBuilder = objBuilder.prop(param.name, valibotType);
168
+ }
169
+ const ast = conjure.id("v").method("object", [objBuilder.build()]).build();
170
+ return {
171
+ ast,
172
+ importSpec: { from: "valibot", names: ["v"] },
173
+ };
174
+ },
246
175
  };
247
- /** Build import refs for used enums */
248
- const buildEnumImports = (usedEnums) => Arr.fromIterable(usedEnums).map(enumName => ({
249
- kind: "symbol",
250
- ref: { capability: "schemas", entity: enumName },
251
- }));
252
- // ============================================================================
253
- // Param Schema Builder (for HTTP plugins)
254
- // ============================================================================
255
- /**
256
- * Build Valibot schema expression for a single param.
257
- * Uses v.pipe(v.string(), v.transform(...)) for type coercion since URL params are strings.
258
- */
259
- const buildParamFieldSchema = (param) => {
260
- const tsType = param.type.toLowerCase();
261
- let fieldSchema;
262
- switch (tsType) {
176
+ function paramToValibotType(param) {
177
+ const baseType = param.type.replace(/\[\]$/, "").replace(/\?$/, "").toLowerCase();
178
+ let valibotSchema;
179
+ switch (baseType) {
263
180
  case "number":
264
- // v.pipe(v.string(), v.transform(Number))
265
- fieldSchema = buildValibotCall("pipe", [
266
- buildValibotCall("string"),
267
- buildValibotCall("transform", [conjure.id("Number").build()]),
268
- ]);
181
+ case "int":
182
+ case "integer":
183
+ case "float":
184
+ case "double":
185
+ valibotSchema = conjure
186
+ .id("v")
187
+ .method("pipe", [
188
+ conjure.id("v").method("string").build(),
189
+ conjure
190
+ .id("v")
191
+ .method("transform", [
192
+ b.arrowFunctionExpression([b.identifier("s")], b.identifier("Number")),
193
+ ])
194
+ .build(),
195
+ ])
196
+ .build();
269
197
  break;
270
198
  case "boolean":
271
- // v.pipe(v.string(), v.transform(v => v === 'true'))
272
- fieldSchema = buildValibotCall("pipe", [
273
- buildValibotCall("string"),
274
- buildValibotCall("transform", [
275
- b.arrowFunctionExpression([b.identifier("v")], b.binaryExpression("===", b.identifier("v"), b.stringLiteral("true"))),
276
- ]),
277
- ]);
199
+ case "bool":
200
+ valibotSchema = conjure
201
+ .id("v")
202
+ .method("pipe", [
203
+ conjure.id("v").method("string").build(),
204
+ conjure
205
+ .id("v")
206
+ .method("transform", [
207
+ b.arrowFunctionExpression([b.identifier("v")], conjure.op.eq(b.identifier("v"), b.stringLiteral("true"))),
208
+ ])
209
+ .build(),
210
+ ])
211
+ .build();
278
212
  break;
279
213
  case "bigint":
280
- // v.pipe(v.string(), v.transform(BigInt))
281
- fieldSchema = buildValibotCall("pipe", [
282
- buildValibotCall("string"),
283
- buildValibotCall("transform", [conjure.id("BigInt").build()]),
284
- ]);
214
+ valibotSchema = conjure
215
+ .id("v")
216
+ .method("pipe", [
217
+ conjure.id("v").method("string").build(),
218
+ conjure
219
+ .id("v")
220
+ .method("transform", [
221
+ b.arrowFunctionExpression([b.identifier("s")], b.identifier("BigInt")),
222
+ ])
223
+ .build(),
224
+ ])
225
+ .build();
285
226
  break;
286
227
  case "date":
287
- // v.pipe(v.string(), v.transform(s => new Date(s)))
288
- fieldSchema = buildValibotCall("pipe", [
289
- buildValibotCall("string"),
290
- buildValibotCall("transform", [
228
+ valibotSchema = conjure
229
+ .id("v")
230
+ .method("pipe", [
231
+ conjure.id("v").method("string").build(),
232
+ conjure
233
+ .id("v")
234
+ .method("transform", [
291
235
  b.arrowFunctionExpression([b.identifier("s")], b.newExpression(b.identifier("Date"), [b.identifier("s")])),
292
- ]),
293
- ]);
236
+ ])
237
+ .build(),
238
+ ])
239
+ .build();
294
240
  break;
295
241
  case "string":
296
242
  default:
297
- // v.string()
298
- fieldSchema = buildValibotCall("string");
243
+ valibotSchema = conjure.id("v").method("string").build();
299
244
  break;
300
245
  }
301
- // Add v.optional(...) for non-required params
302
246
  if (!param.required) {
303
- fieldSchema = wrapOptional(fieldSchema);
247
+ valibotSchema = conjure.id("v").method("optional", [valibotSchema]).build();
304
248
  }
305
- return fieldSchema;
306
- };
307
- /**
308
- * Build v.object({ ... }) expression from QueryMethodParam[].
309
- */
310
- const buildParamValibotObject = (params) => {
311
- const objBuilder = params.reduce((builder, param) => builder.prop(param.name, buildParamFieldSchema(param)), obj());
312
- return buildValibotCall("object", [objBuilder.build()]);
313
- };
314
- /**
315
- * Create a SchemaBuilder implementation for Valibot.
316
- */
317
- const createValibotSchemaBuilder = () => ({
318
- build: (request) => {
319
- if (request.params.length === 0) {
320
- return undefined;
321
- }
322
- const ast = buildParamValibotObject(request.params);
323
- return {
324
- ast,
325
- importSpec: {
326
- namespace: "v",
327
- from: "valibot",
328
- },
329
- };
330
- },
331
- });
332
- // ============================================================================
333
- // Provider Definition
334
- // ============================================================================
335
- /**
336
- * Create a valibot provider that generates Valibot schemas.
337
- *
338
- * @example
339
- * ```typescript
340
- * import { valibot } from "pg-sourcerer"
341
- *
342
- * export default defineConfig({
343
- * plugins: [
344
- * valibot(),
345
- * valibot({ outputDir: "schemas", exportTypes: false }),
346
- * ],
347
- * })
348
- * ```
349
- */
350
- export function valibot(config = {}) {
351
- const parsed = S.decodeUnknownSync(ValibotConfigSchema)(config);
352
- return definePlugin({
249
+ return valibotSchema;
250
+ }
251
+ function getShapeDeclarations(entity) {
252
+ const declarations = [];
253
+ const baseEntityName = entity.name;
254
+ declarations.push({
255
+ name: entity.shapes.row.name,
256
+ capability: `schema:valibot:${entity.shapes.row.name}`,
257
+ baseEntityName,
258
+ });
259
+ if (entity.shapes.insert) {
260
+ const insertName = entity.shapes.insert.name;
261
+ declarations.push({
262
+ name: insertName,
263
+ capability: `schema:valibot:${insertName}`,
264
+ baseEntityName,
265
+ });
266
+ declarations.push({
267
+ name: insertName,
268
+ capability: `schema:valibot:${insertName}:type`,
269
+ baseEntityName,
270
+ });
271
+ }
272
+ if (entity.shapes.update) {
273
+ const updateName = entity.shapes.update.name;
274
+ declarations.push({
275
+ name: updateName,
276
+ capability: `schema:valibot:${updateName}`,
277
+ baseEntityName,
278
+ });
279
+ declarations.push({
280
+ name: updateName,
281
+ capability: `schema:valibot:${updateName}:type`,
282
+ baseEntityName,
283
+ });
284
+ }
285
+ return declarations;
286
+ }
287
+ export function valibot(config) {
288
+ const schemaConfig = S.decodeSync(ValibotSchemaConfig)(config ?? {});
289
+ const resolvedConfig = {
290
+ ...schemaConfig,
291
+ schemasFile: normalizeFileNaming(config?.schemasFile, "schemas.ts"),
292
+ };
293
+ return {
353
294
  name: "valibot",
354
- kind: "schemas",
355
- singleton: true,
356
- canProvide: () => true,
357
- provide: (_params, _deps, ctx) => {
358
- const { ir, inflection } = ctx;
359
- const enumEntities = getEnumEntities(ir);
360
- // Register schema-builder service for on-demand param/query schema generation
361
- ctx.registerHandler(SCHEMA_BUILDER_KIND, createValibotSchemaBuilder().build);
362
- const fieldCtx = {
363
- enums: enumEntities,
364
- extensions: ir.extensions,
365
- enumStyle: parsed.enumStyle,
366
- typeReferences: parsed.typeReferences,
367
- };
368
- // Helper to build file path
369
- const buildFilePath = (entityName) => `${parsed.outputDir}/${entityName}.ts`;
370
- // Generate separate enum files if configured
371
- if (parsed.typeReferences === "separate") {
372
- enumEntities
373
- .filter(e => e.tags.omit !== true)
374
- .forEach(enumEntity => {
375
- const statements = generateEnumStatement(enumEntity, parsed.enumStyle, parsed.exportTypes);
376
- ctx
377
- .file(buildFilePath(enumEntity.name))
378
- .import({ kind: "package", namespace: "v", from: "valibot" })
379
- .ast(conjure.symbolProgram(...statements))
380
- .emit();
381
- });
295
+ provides: ["schema"],
296
+ fileDefaults: [
297
+ {
298
+ pattern: "schema:",
299
+ fileNaming: resolvedConfig.schemasFile,
300
+ },
301
+ ],
302
+ declare: Effect.gen(function* () {
303
+ const ir = yield* IR;
304
+ const declarations = [];
305
+ for (const entity of ir.entities.values()) {
306
+ if (isTableEntity(entity)) {
307
+ declarations.push(...getShapeDeclarations(entity));
308
+ }
309
+ else if (isEnumEntity(entity)) {
310
+ declarations.push({
311
+ name: entity.name,
312
+ capability: `schema:valibot:${entity.name}`,
313
+ baseEntityName: entity.name,
314
+ });
315
+ declarations.push({
316
+ name: entity.name,
317
+ capability: `schema:valibot:${entity.name}:type`,
318
+ baseEntityName: entity.name,
319
+ });
320
+ }
382
321
  }
383
- getTableEntities(ir)
384
- .filter(entity => entity.tags.omit !== true)
385
- .forEach(entity => {
386
- const statements = generateEntityStatements(entity, fieldCtx, parsed.exportTypes);
387
- const entityName = inflection.entityName(entity.pgClass, entity.tags);
388
- // Collect all fields for enum detection
389
- const allFields = [
390
- ...entity.shapes.row.fields,
391
- ...(entity.shapes.insert?.fields ?? []),
392
- ...(entity.shapes.update?.fields ?? []),
393
- ];
394
- const usedEnums = parsed.typeReferences === "separate"
395
- ? collectUsedEnums(allFields, Arr.fromIterable(fieldCtx.enums))
396
- : new Set();
397
- const fileBuilder = ctx
398
- .file(buildFilePath(entityName))
399
- .import({ kind: "package", namespace: "v", from: "valibot" });
400
- // Add enum imports when using separate files
401
- buildEnumImports(usedEnums).forEach(ref => fileBuilder.import(ref));
402
- fileBuilder.ast(conjure.symbolProgram(...statements)).emit();
322
+ declarations.push({
323
+ name: "valibotSchemaBuilder",
324
+ capability: "schema:valibot:builder",
403
325
  });
404
- // Generate composite type schemas
405
- getCompositeEntities(ir)
406
- .filter(composite => composite.tags.omit !== true)
407
- .forEach(composite => {
408
- const statements = generateCompositeStatements(composite, fieldCtx, parsed.exportTypes);
409
- // Collect enum usage for imports
410
- const usedEnums = parsed.typeReferences === "separate"
411
- ? collectUsedEnums(composite.fields, Arr.fromIterable(fieldCtx.enums))
412
- : new Set();
413
- const fileBuilder = ctx
414
- .file(buildFilePath(composite.name))
415
- .import({ kind: "package", namespace: "v", from: "valibot" });
416
- buildEnumImports(usedEnums).forEach(ref => fileBuilder.import(ref));
417
- fileBuilder.ast(conjure.symbolProgram(...statements)).emit();
326
+ return declarations;
327
+ }),
328
+ render: Effect.gen(function* () {
329
+ const ir = yield* IR;
330
+ const registry = yield* SymbolRegistry;
331
+ const enums = [...ir.entities.values()].filter(isEnumEntity);
332
+ const rendered = [];
333
+ for (const entity of ir.entities.values()) {
334
+ if (isTableEntity(entity)) {
335
+ const shapes = [
336
+ entity.shapes.row,
337
+ ];
338
+ if (entity.shapes.insert)
339
+ shapes.push(entity.shapes.insert);
340
+ if (entity.shapes.update)
341
+ shapes.push(entity.shapes.update);
342
+ for (const shape of shapes) {
343
+ const isRow = shape.kind === "row";
344
+ const capability = `schema:valibot:${shape.name}`;
345
+ const schemaNode = registry.forSymbol(capability, () => shapeToValibotObject(shape, enums, registry));
346
+ const schemaDecl = conjure.export.const(shape.name, schemaNode);
347
+ rendered.push({
348
+ name: shape.name,
349
+ capability,
350
+ node: schemaDecl,
351
+ exports: "named",
352
+ externalImports: [{ from: "valibot", names: ["v"] }],
353
+ metadata: {
354
+ consume: createValibotConsumeCallback(shape.name),
355
+ },
356
+ });
357
+ if (resolvedConfig.exportTypes && !isRow) {
358
+ const inferType = conjure.ts.qualifiedRef("v", "InferOutput", [
359
+ conjure.ts.typeof(shape.name),
360
+ ]);
361
+ const typeDecl = conjure.export.type(shape.name, inferType);
362
+ rendered.push({
363
+ name: shape.name,
364
+ capability: `schema:valibot:${shape.name}:type`,
365
+ node: typeDecl,
366
+ exports: "named",
367
+ externalImports: [{ from: "valibot", names: ["v"] }],
368
+ });
369
+ }
370
+ }
371
+ }
372
+ else if (isEnumEntity(entity)) {
373
+ const schemaNode = conjure
374
+ .id("v")
375
+ .method("picklist", [conjure.arr(...entity.values.map(v => conjure.str(v))).build()])
376
+ .build();
377
+ const schemaDecl = conjure.export.const(entity.name, schemaNode);
378
+ const inferType = conjure.ts.qualifiedRef("v", "InferOutput", [
379
+ conjure.ts.typeof(entity.name),
380
+ ]);
381
+ const typeDecl = conjure.export.type(entity.name, inferType);
382
+ rendered.push({
383
+ name: entity.name,
384
+ capability: `schema:valibot:${entity.name}`,
385
+ node: schemaDecl,
386
+ exports: "named",
387
+ externalImports: [{ from: "valibot", names: ["v"] }],
388
+ metadata: {
389
+ consume: createValibotConsumeCallback(entity.name),
390
+ },
391
+ });
392
+ if (resolvedConfig.exportTypes) {
393
+ rendered.push({
394
+ name: entity.name,
395
+ capability: `schema:valibot:${entity.name}:type`,
396
+ node: typeDecl,
397
+ exports: "named",
398
+ externalImports: [{ from: "valibot", names: ["v"] }],
399
+ });
400
+ }
401
+ }
402
+ }
403
+ rendered.push({
404
+ name: "valibotSchemaBuilder",
405
+ capability: "schema:valibot:builder",
406
+ node: null,
407
+ exports: false,
408
+ metadata: {
409
+ builder: valibotSchemaBuilder,
410
+ },
418
411
  });
419
- },
420
- });
412
+ return rendered;
413
+ }),
414
+ };
421
415
  }
422
416
  //# sourceMappingURL=valibot.js.map