@metaobjectsdev/codegen-ts 0.5.0-rc.1

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 (198) hide show
  1. package/LICENSE +189 -0
  2. package/README.md +101 -0
  3. package/dist/column-mapper.d.ts +38 -0
  4. package/dist/column-mapper.d.ts.map +1 -0
  5. package/dist/column-mapper.js +205 -0
  6. package/dist/column-mapper.js.map +1 -0
  7. package/dist/constants.d.ts +7 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +8 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/errors.d.ts +7 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +11 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/format.d.ts +2 -0
  16. package/dist/format.d.ts.map +1 -0
  17. package/dist/format.js +47 -0
  18. package/dist/format.js.map +1 -0
  19. package/dist/generator.d.ts +44 -0
  20. package/dist/generator.d.ts.map +1 -0
  21. package/dist/generator.js +17 -0
  22. package/dist/generator.js.map +1 -0
  23. package/dist/generators/barrel.d.ts +6 -0
  24. package/dist/generators/barrel.d.ts.map +1 -0
  25. package/dist/generators/barrel.js +17 -0
  26. package/dist/generators/barrel.js.map +1 -0
  27. package/dist/generators/entity-file.d.ts +8 -0
  28. package/dist/generators/entity-file.d.ts.map +1 -0
  29. package/dist/generators/entity-file.js +27 -0
  30. package/dist/generators/entity-file.js.map +1 -0
  31. package/dist/generators/index.d.ts +5 -0
  32. package/dist/generators/index.d.ts.map +1 -0
  33. package/dist/generators/index.js +5 -0
  34. package/dist/generators/index.js.map +1 -0
  35. package/dist/generators/queries-file.d.ts +8 -0
  36. package/dist/generators/queries-file.d.ts.map +1 -0
  37. package/dist/generators/queries-file.js +26 -0
  38. package/dist/generators/queries-file.js.map +1 -0
  39. package/dist/generators/routes-file.d.ts +12 -0
  40. package/dist/generators/routes-file.d.ts.map +1 -0
  41. package/dist/generators/routes-file.js +30 -0
  42. package/dist/generators/routes-file.js.map +1 -0
  43. package/dist/import-path.d.ts +41 -0
  44. package/dist/import-path.d.ts.map +1 -0
  45. package/dist/import-path.js +95 -0
  46. package/dist/import-path.js.map +1 -0
  47. package/dist/index.d.ts +29 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +21 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/metaobjects-config.d.ts +56 -0
  52. package/dist/metaobjects-config.d.ts.map +1 -0
  53. package/dist/metaobjects-config.js +42 -0
  54. package/dist/metaobjects-config.js.map +1 -0
  55. package/dist/naming.d.ts +29 -0
  56. package/dist/naming.d.ts.map +1 -0
  57. package/dist/naming.js +67 -0
  58. package/dist/naming.js.map +1 -0
  59. package/dist/overwrite-policy.d.ts +8 -0
  60. package/dist/overwrite-policy.d.ts.map +1 -0
  61. package/dist/overwrite-policy.js +23 -0
  62. package/dist/overwrite-policy.js.map +1 -0
  63. package/dist/pk-resolver.d.ts +18 -0
  64. package/dist/pk-resolver.d.ts.map +1 -0
  65. package/dist/pk-resolver.js +36 -0
  66. package/dist/pk-resolver.js.map +1 -0
  67. package/dist/projection/extract-view-spec.d.ts +18 -0
  68. package/dist/projection/extract-view-spec.d.ts.map +1 -0
  69. package/dist/projection/extract-view-spec.js +272 -0
  70. package/dist/projection/extract-view-spec.js.map +1 -0
  71. package/dist/projection/index.d.ts +5 -0
  72. package/dist/projection/index.d.ts.map +1 -0
  73. package/dist/projection/index.js +5 -0
  74. package/dist/projection/index.js.map +1 -0
  75. package/dist/projection/projection-detector.d.ts +4 -0
  76. package/dist/projection/projection-detector.d.ts.map +1 -0
  77. package/dist/projection/projection-detector.js +13 -0
  78. package/dist/projection/projection-detector.js.map +1 -0
  79. package/dist/projection/view-ddl-emit.d.ts +10 -0
  80. package/dist/projection/view-ddl-emit.d.ts.map +1 -0
  81. package/dist/projection/view-ddl-emit.js +47 -0
  82. package/dist/projection/view-ddl-emit.js.map +1 -0
  83. package/dist/projection/view-spec.d.ts +56 -0
  84. package/dist/projection/view-spec.d.ts.map +1 -0
  85. package/dist/projection/view-spec.js +2 -0
  86. package/dist/projection/view-spec.js.map +1 -0
  87. package/dist/relation-resolver.d.ts +21 -0
  88. package/dist/relation-resolver.d.ts.map +1 -0
  89. package/dist/relation-resolver.js +62 -0
  90. package/dist/relation-resolver.js.map +1 -0
  91. package/dist/render-context.d.ts +65 -0
  92. package/dist/render-context.d.ts.map +1 -0
  93. package/dist/render-context.js +28 -0
  94. package/dist/render-context.js.map +1 -0
  95. package/dist/runner.d.ts +17 -0
  96. package/dist/runner.d.ts.map +1 -0
  97. package/dist/runner.js +135 -0
  98. package/dist/runner.js.map +1 -0
  99. package/dist/templates/barrel.d.ts +8 -0
  100. package/dist/templates/barrel.d.ts.map +1 -0
  101. package/dist/templates/barrel.js +12 -0
  102. package/dist/templates/barrel.js.map +1 -0
  103. package/dist/templates/drizzle-schema.d.ts +13 -0
  104. package/dist/templates/drizzle-schema.d.ts.map +1 -0
  105. package/dist/templates/drizzle-schema.js +251 -0
  106. package/dist/templates/drizzle-schema.js.map +1 -0
  107. package/dist/templates/entity-constants.d.ts +4 -0
  108. package/dist/templates/entity-constants.d.ts.map +1 -0
  109. package/dist/templates/entity-constants.js +215 -0
  110. package/dist/templates/entity-constants.js.map +1 -0
  111. package/dist/templates/entity-file.d.ts +4 -0
  112. package/dist/templates/entity-file.d.ts.map +1 -0
  113. package/dist/templates/entity-file.js +45 -0
  114. package/dist/templates/entity-file.js.map +1 -0
  115. package/dist/templates/field-meta.d.ts +24 -0
  116. package/dist/templates/field-meta.d.ts.map +1 -0
  117. package/dist/templates/field-meta.js +117 -0
  118. package/dist/templates/field-meta.js.map +1 -0
  119. package/dist/templates/filter-allowlist.d.ts +5 -0
  120. package/dist/templates/filter-allowlist.d.ts.map +1 -0
  121. package/dist/templates/filter-allowlist.js +86 -0
  122. package/dist/templates/filter-allowlist.js.map +1 -0
  123. package/dist/templates/filter-shared.d.ts +15 -0
  124. package/dist/templates/filter-shared.d.ts.map +1 -0
  125. package/dist/templates/filter-shared.js +30 -0
  126. package/dist/templates/filter-shared.js.map +1 -0
  127. package/dist/templates/filter-type.d.ts +4 -0
  128. package/dist/templates/filter-type.d.ts.map +1 -0
  129. package/dist/templates/filter-type.js +78 -0
  130. package/dist/templates/filter-type.js.map +1 -0
  131. package/dist/templates/inferred-types.d.ts +4 -0
  132. package/dist/templates/inferred-types.d.ts.map +1 -0
  133. package/dist/templates/inferred-types.js +14 -0
  134. package/dist/templates/inferred-types.js.map +1 -0
  135. package/dist/templates/projection-decl.d.ts +21 -0
  136. package/dist/templates/projection-decl.d.ts.map +1 -0
  137. package/dist/templates/projection-decl.js +116 -0
  138. package/dist/templates/projection-decl.js.map +1 -0
  139. package/dist/templates/queries-file.d.ts +4 -0
  140. package/dist/templates/queries-file.d.ts.map +1 -0
  141. package/dist/templates/queries-file.js +39 -0
  142. package/dist/templates/queries-file.js.map +1 -0
  143. package/dist/templates/queries.d.ts +9 -0
  144. package/dist/templates/queries.d.ts.map +1 -0
  145. package/dist/templates/queries.js +115 -0
  146. package/dist/templates/queries.js.map +1 -0
  147. package/dist/templates/relations-block.d.ts +9 -0
  148. package/dist/templates/relations-block.d.ts.map +1 -0
  149. package/dist/templates/relations-block.js +45 -0
  150. package/dist/templates/relations-block.js.map +1 -0
  151. package/dist/templates/routes-file.d.ts +4 -0
  152. package/dist/templates/routes-file.d.ts.map +1 -0
  153. package/dist/templates/routes-file.js +158 -0
  154. package/dist/templates/routes-file.js.map +1 -0
  155. package/dist/templates/zod-validators.d.ts +4 -0
  156. package/dist/templates/zod-validators.d.ts.map +1 -0
  157. package/dist/templates/zod-validators.js +129 -0
  158. package/dist/templates/zod-validators.js.map +1 -0
  159. package/package.json +59 -0
  160. package/src/column-mapper.ts +266 -0
  161. package/src/constants.ts +10 -0
  162. package/src/errors.ts +10 -0
  163. package/src/format.ts +50 -0
  164. package/src/generator.ts +73 -0
  165. package/src/generators/barrel.ts +28 -0
  166. package/src/generators/entity-file.ts +33 -0
  167. package/src/generators/index.ts +4 -0
  168. package/src/generators/queries-file.ts +32 -0
  169. package/src/generators/routes-file.ts +36 -0
  170. package/src/import-path.ts +153 -0
  171. package/src/index.ts +45 -0
  172. package/src/metaobjects-config.ts +95 -0
  173. package/src/naming.ts +84 -0
  174. package/src/overwrite-policy.ts +39 -0
  175. package/src/pk-resolver.ts +47 -0
  176. package/src/projection/extract-view-spec.ts +372 -0
  177. package/src/projection/index.ts +4 -0
  178. package/src/projection/projection-detector.ts +26 -0
  179. package/src/projection/view-ddl-emit.ts +66 -0
  180. package/src/projection/view-spec.ts +62 -0
  181. package/src/relation-resolver.ts +87 -0
  182. package/src/render-context.ts +93 -0
  183. package/src/runner.ts +178 -0
  184. package/src/templates/barrel.ts +23 -0
  185. package/src/templates/drizzle-schema.ts +286 -0
  186. package/src/templates/entity-constants.ts +248 -0
  187. package/src/templates/entity-file.ts +51 -0
  188. package/src/templates/field-meta.ts +150 -0
  189. package/src/templates/filter-allowlist.ts +104 -0
  190. package/src/templates/filter-shared.ts +30 -0
  191. package/src/templates/filter-type.ts +93 -0
  192. package/src/templates/inferred-types.ts +16 -0
  193. package/src/templates/projection-decl.ts +146 -0
  194. package/src/templates/queries-file.ts +56 -0
  195. package/src/templates/queries.ts +132 -0
  196. package/src/templates/relations-block.ts +65 -0
  197. package/src/templates/routes-file.ts +179 -0
  198. package/src/templates/zod-validators.ts +140 -0
package/LICENSE ADDED
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of recording and
55
+ discussing modifications to the Work, but excluding communication that
56
+ is conspicuously marked or designated in writing by the copyright owner
57
+ as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, reproduce, modify,
120
+ prepare derivative works of, distribute, and sublicense such modifications,
121
+ as an additional requirement of this License.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any conditions of TITLE,
141
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
142
+ PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer
163
+ only obligations consistent to this License provided that the
164
+ obligations are consistent with this License.
165
+
166
+ END OF TERMS AND CONDITIONS
167
+
168
+ APPENDIX: How to apply the Apache License to your work.
169
+
170
+ To apply the Apache License to your work, attach the following
171
+ boilerplate notice, with the fields enclosed by brackets "[]"
172
+ replaced with your own identifying information. (Don't include
173
+ the brackets!) The text should be enclosed in the appropriate
174
+ comment syntax for the file format in question. Also add information
175
+ on how to contact you electronically and/or by mail.
176
+
177
+ Copyright 2026 MetaObjects Contributors
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @metaobjectsdev/codegen-ts
2
+
3
+ TypeScript codegen for the metaobjects metamodel — emits Drizzle schema +
4
+ inferred types + Zod validators + typed CRUD queries from a loaded `MetaData`.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install @metaobjectsdev/codegen-ts @metaobjectsdev/metadata drizzle-orm zod
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```typescript
15
+ import { FileMetaDataLoader } from "@metaobjectsdev/metadata/core";
16
+ import { generate } from "@metaobjectsdev/codegen-ts";
17
+
18
+ const loader = new FileMetaDataLoader();
19
+ const { root } = await loader.loadFiles(["metaobjects/meta.blog.json"]);
20
+
21
+ const result = await generate({
22
+ metadata: root,
23
+ outDir: "./src/db/entities",
24
+ dialect: "sqlite",
25
+ dbImport: "~/server/db", // path to your { db } export
26
+ });
27
+
28
+ for (const f of result.files) console.log(f.status, f.path);
29
+ ```
30
+
31
+ ## Output
32
+
33
+ Per entity, codegen emits **two files**:
34
+
35
+ - `<Entity>.ts` — Drizzle table definition (with FK `.references()` + `relations()` blocks
36
+ auto-emitted from metadata relationships) + Drizzle-inferred types + Zod validators
37
+ - `<Entity>.queries.ts` — typed CRUD query functions with prepared statements
38
+ (`findPostById`, `listPosts`, `createPost`, `updatePost`, `deletePostById`)
39
+
40
+ Plus a barrel `index.ts` re-exporting from each `<Entity>.ts`.
41
+
42
+ ```typescript
43
+ // Use the entity types and table:
44
+ import { posts, type Post, PostInsertSchema } from './db/entities/Post.js';
45
+
46
+ // Use the typed CRUD queries:
47
+ import { findPostById, createPost } from './db/entities/Post.queries.js';
48
+
49
+ const post = await findPostById(42);
50
+ const newPost = await createPost({ title: 'Hello', body: 'World', authorId: 1 });
51
+ ```
52
+
53
+ Generated files carry an `@generated by @metaobjectsdev/codegen-ts` header.
54
+ codegen-ts overwrites files with the header but refuses to touch files
55
+ without it. Hand-customizations live in sibling `<Entity>.extra.ts` files
56
+ (for custom queries, derived-column indexes, etc. that metadata can't express).
57
+
58
+ ## Output targets
59
+
60
+ Each generator can be routed to its own output directory via a named **target**
61
+ (see the CLI's `defineConfig` — `@metaobjectsdev/cli` README, "Multiple output
62
+ targets"). The runner gives every generator a `RenderContext` carrying its own
63
+ `selfTarget` and the shared `entityModuleTarget` (where `entityFile()` output
64
+ lives), then writes each emitted file under its target's `outDir` (collisions are
65
+ keyed on the resolved full path, so the same filename in two targets is fine).
66
+
67
+ Templates resolve the entity-module import through `entityModuleSpecifier(selfTarget,
68
+ entityModuleTarget, pkg, name, extStyle)`:
69
+
70
+ - **same target** → relative (`./Program`), honoring `extStyle`
71
+ - **cross target** → extension-less package path from the entity-module target's
72
+ `importBase` (`@acme/database/generated/acme/commerce/Program`)
73
+
74
+ Companion helpers: `siblingSpecifier` (same-target sibling module, e.g.
75
+ `<Entity>.columns`) and `barrelModuleSpecifier` (barrel re-exports). A generator
76
+ declares it produces the entity module with `emitsEntityModule: true` (set by
77
+ `entityFile()`); the runner derives the entity-module target from it. With a single
78
+ target, every specifier takes the relative branch, so output is unchanged.
79
+
80
+ ## Dialects
81
+
82
+ - `sqlite` — emits `sqliteTable`, `text`, `integer`, etc. from `drizzle-orm/sqlite-core`
83
+ - `postgres` — emits `pgTable`, `varchar`, `bigint`, etc. from `drizzle-orm/pg-core`
84
+
85
+ ## Driver compatibility
86
+
87
+ Generated `<Entity>.queries.ts` files use Drizzle's `.returning()` API in
88
+ `create*` and `update*` functions. This works on:
89
+
90
+ - `libsql` / Turso
91
+ - `node-postgres` (`pg`)
92
+ - `@neondatabase/serverless`
93
+
94
+ It does **not** work on `better-sqlite3` or `bun:sqlite` (no native
95
+ `RETURNING` support). Users on those drivers should override the affected
96
+ functions in the sibling `<Entity>.extra.ts` file with a non-`.returning()`
97
+ form, or switch to a supported driver.
98
+
99
+ ## License
100
+
101
+ Apache-2.0.
@@ -0,0 +1,38 @@
1
+ import type { MetaField } from "@metaobjectsdev/metadata";
2
+ import type { Dialect, ColumnNamingStrategy } from "./metaobjects-config.js";
3
+ export type { Dialect };
4
+ /**
5
+ * Discriminated union describing how a column default should be emitted.
6
+ * - { kind: "now" } — dialect-aware: sql`CURRENT_TIMESTAMP` (sqlite) or .defaultNow() (postgres)
7
+ * - { kind: "sqlExpr"; raw } — raw SQL expression wrapped in sql`...` (CURRENT_DATE, CURRENT_TIME, function calls)
8
+ * - { kind: "literal"; value } — .default(JSON.stringify(value))
9
+ */
10
+ export type DefaultExpr = {
11
+ kind: "now";
12
+ } | {
13
+ kind: "sqlExpr";
14
+ raw: string;
15
+ } | {
16
+ kind: "literal";
17
+ value: unknown;
18
+ };
19
+ export interface ColumnSpec {
20
+ /** Drizzle function name, e.g., "text", "integer", "varchar". */
21
+ fnName: string;
22
+ /** DB column name (snake_case from field name, or @dbColumn override). */
23
+ dbName: string;
24
+ /** Positional args after dbName (currently always empty; reserved). */
25
+ fnArgs: unknown[];
26
+ /** Object passed as second arg if non-empty (e.g., { length: 200 }, { mode: 'boolean' }). */
27
+ fnOptions?: Record<string, unknown>;
28
+ /** Method chain modifiers, e.g., [".notNull()", ".unique()"]. */
29
+ modifiers: string[];
30
+ /** Default expression for the column — dialect-specific emission handled by the template. */
31
+ defaultExpr?: DefaultExpr;
32
+ /** Drizzle import module: "drizzle-orm/sqlite-core" or "drizzle-orm/pg-core". */
33
+ importModule: string;
34
+ /** Optional leading line-comment for the generated column (e.g., type-fallback notice). */
35
+ leadingComment?: string;
36
+ }
37
+ export declare function mapColumnType(field: MetaField, dialect: Dialect, strategy?: ColumnNamingStrategy): ColumnSpec;
38
+ //# sourceMappingURL=column-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-mapper.d.ts","sourceRoot":"","sources":["../src/column-mapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAyB1D,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE7E,YAAY,EAAE,OAAO,EAAE,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAiCxC,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,iEAAiE;IACjE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,6FAA6F;IAC7F,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,iFAAiF;IACjF,YAAY,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAuBD,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,OAAO,EAChB,QAAQ,GAAE,oBAAmC,GAC5C,UAAU,CAmJZ"}
@@ -0,0 +1,205 @@
1
+ // Field-type → Drizzle column type mapping. Per design §6.
2
+ // Uses the typed MetaField.validators() accessor (effective — includes inherited) for all validator checks.
3
+ import { FIELD_SUBTYPE_STRING, FIELD_SUBTYPE_INT, FIELD_SUBTYPE_LONG, FIELD_SUBTYPE_CURRENCY, FIELD_SUBTYPE_DOUBLE, FIELD_SUBTYPE_FLOAT, FIELD_SUBTYPE_DECIMAL, FIELD_SUBTYPE_BOOLEAN, FIELD_SUBTYPE_DATE, FIELD_SUBTYPE_TIME, FIELD_SUBTYPE_TIMESTAMP, FIELD_SUBTYPE_OBJECT, FIELD_SUBTYPE_CLASS, VALIDATOR_SUBTYPE_REQUIRED, VALIDATOR_SUBTYPE_LENGTH, FIELD_ATTR_MAX_LENGTH, FIELD_ATTR_REQUIRED, FIELD_ATTR_DB_COLUMN, FIELD_ATTR_UNIQUE, FIELD_ATTR_DEFAULT, VALIDATOR_ATTR_MAX, } from "@metaobjectsdev/metadata";
4
+ import { columnNameFromField } from "./naming.js";
5
+ /**
6
+ * Patterns recognized as SQL expressions in a default value. Anything matching
7
+ * these is treated as a SQL expression, not a string literal. Mirrors
8
+ * migrate-ts/src/expected-schema.ts's EXPR_DEFAULT_PATTERNS so both sides
9
+ * agree on what's an expression.
10
+ */
11
+ const SQL_EXPR_PATTERNS = [
12
+ /^now$/i,
13
+ /^now\(\)$/i,
14
+ /^current_timestamp$/i,
15
+ /^current_date$/i,
16
+ /^current_time$/i,
17
+ /\(\)$/, // anything function-like
18
+ ];
19
+ /** True iff the value should be emitted as a SQL expression. */
20
+ function isSqlExprDefault(value) {
21
+ return SQL_EXPR_PATTERNS.some((re) => re.test(value));
22
+ }
23
+ /** Map a recognized SQL expression to its canonical raw form (uppercase keywords). */
24
+ function canonicalizeSqlExpr(value) {
25
+ const lower = value.toLowerCase();
26
+ if (lower === "now" || lower === "now()" || lower === "current_timestamp") {
27
+ return "CURRENT_TIMESTAMP";
28
+ }
29
+ if (lower === "current_date")
30
+ return "CURRENT_DATE";
31
+ if (lower === "current_time")
32
+ return "CURRENT_TIME";
33
+ return value; // unrecognized — pass through (function calls etc.)
34
+ }
35
+ /** Resolve max length from validator.length child or @maxLength attr.
36
+ * Uses field.validators() (effective) so inherited validators are seen. */
37
+ function getMaxLength(field) {
38
+ const lenAttr = field.ownAttr(FIELD_ATTR_MAX_LENGTH);
39
+ if (typeof lenAttr === "number")
40
+ return lenAttr;
41
+ for (const child of field.validators()) {
42
+ if (child.subType === VALIDATOR_SUBTYPE_LENGTH) {
43
+ const max = child.ownAttr(VALIDATOR_ATTR_MAX);
44
+ if (typeof max === "number")
45
+ return max;
46
+ }
47
+ }
48
+ return undefined;
49
+ }
50
+ /** Check for validator.required child OR @required attr.
51
+ * Uses field.validators() (effective) so inherited validators are seen. */
52
+ function isRequired(field) {
53
+ if (field.ownAttr(FIELD_ATTR_REQUIRED) === true)
54
+ return true;
55
+ return field.validators().some((child) => child.subType === VALIDATOR_SUBTYPE_REQUIRED);
56
+ }
57
+ export function mapColumnType(field, dialect, strategy = "snake_case") {
58
+ const dbName = field.ownAttr(FIELD_ATTR_DB_COLUMN) ?? columnNameFromField(field.name, strategy);
59
+ const importModule = dialect === "sqlite" ? "drizzle-orm/sqlite-core" : "drizzle-orm/pg-core";
60
+ const subType = field.subType;
61
+ const isArray = field.isArray;
62
+ let fnName;
63
+ let fnOptions;
64
+ let leadingComment;
65
+ if (dialect === "sqlite") {
66
+ if (isArray) {
67
+ // SQLite has no native array type; serialize as JSON in a text column.
68
+ fnName = "text";
69
+ fnOptions = { mode: "json" };
70
+ }
71
+ else {
72
+ switch (subType) {
73
+ case FIELD_SUBTYPE_BOOLEAN:
74
+ fnName = "integer";
75
+ fnOptions = { mode: "boolean" };
76
+ break;
77
+ case FIELD_SUBTYPE_INT:
78
+ case FIELD_SUBTYPE_CURRENCY:
79
+ case FIELD_SUBTYPE_LONG:
80
+ fnName = "integer";
81
+ break;
82
+ case FIELD_SUBTYPE_DOUBLE:
83
+ case FIELD_SUBTYPE_FLOAT:
84
+ fnName = "real";
85
+ break;
86
+ case FIELD_SUBTYPE_DECIMAL:
87
+ fnName = "text";
88
+ // SQLite has no decimal type; the user must do precision math at the app
89
+ // layer or migrate to Postgres. Surface this in the generated file so it
90
+ // isn't a silent rounding hazard.
91
+ leadingComment = "TODO: SQLite has no decimal type; stored as text. Convert at the application boundary or migrate to Postgres for native numeric.";
92
+ break;
93
+ case FIELD_SUBTYPE_DATE:
94
+ case FIELD_SUBTYPE_TIME:
95
+ case FIELD_SUBTYPE_TIMESTAMP:
96
+ case FIELD_SUBTYPE_STRING:
97
+ case FIELD_SUBTYPE_CLASS:
98
+ case FIELD_SUBTYPE_OBJECT:
99
+ default:
100
+ fnName = "text";
101
+ break;
102
+ }
103
+ }
104
+ }
105
+ else {
106
+ switch (subType) {
107
+ case FIELD_SUBTYPE_BOOLEAN:
108
+ fnName = "boolean";
109
+ break;
110
+ case FIELD_SUBTYPE_INT:
111
+ fnName = "integer";
112
+ break;
113
+ case FIELD_SUBTYPE_CURRENCY:
114
+ case FIELD_SUBTYPE_LONG:
115
+ fnName = "bigint";
116
+ fnOptions = { mode: "number" };
117
+ break;
118
+ case FIELD_SUBTYPE_DOUBLE:
119
+ fnName = "doublePrecision";
120
+ break;
121
+ case FIELD_SUBTYPE_FLOAT:
122
+ fnName = "real";
123
+ break;
124
+ case FIELD_SUBTYPE_DATE:
125
+ fnName = "date";
126
+ break;
127
+ case FIELD_SUBTYPE_TIME:
128
+ fnName = "time";
129
+ break;
130
+ case FIELD_SUBTYPE_TIMESTAMP:
131
+ fnName = "timestamp";
132
+ break;
133
+ case FIELD_SUBTYPE_DECIMAL:
134
+ fnName = "numeric";
135
+ fnOptions = { precision: 19, scale: 4 }; // sane default; @precision/@scale attrs override
136
+ break;
137
+ case FIELD_SUBTYPE_STRING: {
138
+ const maxLen = getMaxLength(field);
139
+ if (maxLen !== undefined) {
140
+ fnName = "varchar";
141
+ fnOptions = { length: maxLen };
142
+ }
143
+ else {
144
+ fnName = "text";
145
+ }
146
+ break;
147
+ }
148
+ case FIELD_SUBTYPE_CLASS:
149
+ case FIELD_SUBTYPE_OBJECT:
150
+ default:
151
+ fnName = "text";
152
+ break;
153
+ }
154
+ }
155
+ const modifiers = [];
156
+ if (dialect === "postgres" && isArray) {
157
+ modifiers.push(".array()");
158
+ }
159
+ if (isRequired(field)) {
160
+ modifiers.push(".notNull()");
161
+ }
162
+ if (field.ownAttr(FIELD_ATTR_UNIQUE) === true) {
163
+ modifiers.push(".unique()");
164
+ }
165
+ let defaultExpr;
166
+ const defaultAttr = field.ownAttr(FIELD_ATTR_DEFAULT);
167
+ if (defaultAttr !== undefined) {
168
+ // SQL-expression detection runs on the raw string value — a string like
169
+ // "CURRENT_TIMESTAMP" or "now" must be emitted as sql`...`, not a literal.
170
+ if (typeof defaultAttr === "string" && isSqlExprDefault(defaultAttr)) {
171
+ const canonical = canonicalizeSqlExpr(defaultAttr);
172
+ // "now"/"CURRENT_TIMESTAMP" gets the dialect-aware emit path (defaultNow for postgres);
173
+ // other SQL keywords go through the generic sqlExpr emit.
174
+ if (canonical === "CURRENT_TIMESTAMP") {
175
+ defaultExpr = { kind: "now" };
176
+ }
177
+ else {
178
+ defaultExpr = { kind: "sqlExpr", raw: canonical };
179
+ }
180
+ }
181
+ else {
182
+ // Literal branch: use the field-type-converted value so booleans/numbers
183
+ // are real JS booleans/numbers (not strings). field.defaultValue() applies
184
+ // convertToDataType(field.dataType, raw) — Java parity with getDefaultValue().
185
+ // JSON.stringify(false) → "false", JSON.stringify(0) → "0" (unquoted) in templates.
186
+ const typedValue = field.defaultValue() ?? defaultAttr;
187
+ defaultExpr = { kind: "literal", value: typedValue };
188
+ }
189
+ }
190
+ const result = {
191
+ fnName,
192
+ dbName,
193
+ fnArgs: [],
194
+ modifiers,
195
+ importModule,
196
+ };
197
+ if (fnOptions !== undefined)
198
+ result.fnOptions = fnOptions;
199
+ if (defaultExpr !== undefined)
200
+ result.defaultExpr = defaultExpr;
201
+ if (leadingComment !== undefined)
202
+ result.leadingComment = leadingComment;
203
+ return result;
204
+ }
205
+ //# sourceMappingURL=column-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-mapper.js","sourceRoot":"","sources":["../src/column-mapper.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,4GAA4G;AAG5G,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAgBlD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAa;IAClC,QAAQ;IACR,YAAY;IACZ,sBAAsB;IACtB,iBAAiB;IACjB,iBAAiB;IACjB,OAAO,EAAiB,yBAAyB;CAClD,CAAC;AAEF,gEAAgE;AAChE,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,sFAAsF;AACtF,SAAS,mBAAmB,CAAC,KAAa;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,WA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C;QACvD,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAe;QACzB,MAAM;QACN,MAAM;QACN,MAAM,EAAE,EAAE;QACV,SAAS;QACT,YAAY;KACb,CAAC;IACF,IAAI,SAAS,KAAK,SAAS;QAAE,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;IAC1D,IAAI,WAAW,KAAK,SAAS;QAAE,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;IAChE,IAAI,cAAc,KAAK,SAAS;QAAE,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC;IACzE,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** The marker that says "codegen owns this file" — drives the overwrite policy. */
2
+ export declare const GENERATED_HEADER = "@generated by @metaobjectsdev/codegen-ts";
3
+ /** Suffix for sibling user extension files (codegen never touches these). */
4
+ export declare const EXTRA_SUFFIX = ".extra";
5
+ /** Default outDir used by tests + as a sane default for generate(). */
6
+ export declare const DEFAULT_OUT_DIR = "./src/db/entities";
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,eAAO,MAAM,gBAAgB,6CAA6C,CAAC;AAE3E,6EAA6E;AAC7E,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,uEAAuE;AACvE,eAAO,MAAM,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Local constants for codegen-ts.
2
+ /** The marker that says "codegen owns this file" — drives the overwrite policy. */
3
+ export const GENERATED_HEADER = "@generated by @metaobjectsdev/codegen-ts";
4
+ /** Suffix for sibling user extension files (codegen never touches these). */
5
+ export const EXTRA_SUFFIX = ".extra";
6
+ /** Default outDir used by tests + as a sane default for generate(). */
7
+ export const DEFAULT_OUT_DIR = "./src/db/entities";
8
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAElC,mFAAmF;AACnF,MAAM,CAAC,MAAM,gBAAgB,GAAG,0CAA0C,CAAC;AAE3E,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,uEAAuE;AACvE,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare class CodegenError extends Error {
2
+ readonly file?: string;
3
+ constructor(message: string, opts?: {
4
+ file?: string;
5
+ });
6
+ }
7
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBACX,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;CAKtD"}
package/dist/errors.js ADDED
@@ -0,0 +1,11 @@
1
+ // Typed errors for codegen-ts.
2
+ export class CodegenError extends Error {
3
+ file;
4
+ constructor(message, opts) {
5
+ super(message);
6
+ this.name = "CodegenError";
7
+ if (opts?.file !== undefined)
8
+ this.file = opts.file;
9
+ }
10
+ }
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAU;IACvB,YAAY,OAAe,EAAE,IAAwB;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,IAAI,EAAE,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACtD,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export declare function formatTs(content: string): Promise<string>;
2
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAoCA,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa/D"}
package/dist/format.js ADDED
@@ -0,0 +1,47 @@
1
+ // Biome formatter integration. Used by generate() to format rendered TS before write.
2
+ // Per design §11: format errors are warnings, not throws.
3
+ import { Biome, Distribution } from "@biomejs/js-api";
4
+ // Cache the Promise (not the resolved instance) so concurrent first calls
5
+ // share the same in-flight Biome.create() rather than racing to spawn two.
6
+ let _biomePromise;
7
+ function getBiome() {
8
+ if (!_biomePromise) {
9
+ _biomePromise = Biome.create({ distribution: Distribution.NODE }).then((biome) => {
10
+ biome.applyConfiguration({
11
+ formatter: { enabled: true, indentStyle: "space", indentWidth: 2 },
12
+ javascript: { formatter: { quoteStyle: "double", semicolons: "always" } },
13
+ });
14
+ return biome;
15
+ });
16
+ }
17
+ return _biomePromise;
18
+ }
19
+ /**
20
+ * Summarize Biome diagnostics into a single human-readable line, without
21
+ * dumping the raw diagnostic objects (which produce "[Object ...]" /
22
+ * "source: null" noise when stringified by console).
23
+ */
24
+ function summarizeDiagnostics(diagnostics) {
25
+ const count = diagnostics.length;
26
+ const first = diagnostics[0];
27
+ const firstMsg = first?.description ?? first?.message ?? "(no description)";
28
+ return count === 1
29
+ ? `1 diagnostic: ${firstMsg}`
30
+ : `${count} diagnostics; first: ${firstMsg}`;
31
+ }
32
+ export async function formatTs(content) {
33
+ try {
34
+ const biome = await getBiome();
35
+ const result = biome.formatContent(content, { filePath: "in-memory.ts" });
36
+ if (result.diagnostics.length > 0) {
37
+ console.warn(`[codegen-ts] Biome formatter: ${summarizeDiagnostics(result.diagnostics)}`);
38
+ return content;
39
+ }
40
+ return result.content;
41
+ }
42
+ catch (err) {
43
+ console.warn(`[codegen-ts] Biome formatter error: ${err.message}`);
44
+ return content;
45
+ }
46
+ }
47
+ //# sourceMappingURL=format.js.map