@pattern-stack/codegen 0.2.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 (279) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +214 -0
  3. package/dist/runtime/analytics/index.d.ts +6 -0
  4. package/dist/runtime/analytics/index.js +49 -0
  5. package/dist/runtime/analytics/index.js.map +1 -0
  6. package/dist/runtime/analytics/metrics.d.ts +75 -0
  7. package/dist/runtime/analytics/metrics.js +1 -0
  8. package/dist/runtime/analytics/metrics.js.map +1 -0
  9. package/dist/runtime/analytics/packs/crm-entity-measures.d.ts +21 -0
  10. package/dist/runtime/analytics/packs/crm-entity-measures.js +1 -0
  11. package/dist/runtime/analytics/packs/crm-entity-measures.js.map +1 -0
  12. package/dist/runtime/analytics/packs/index.d.ts +3 -0
  13. package/dist/runtime/analytics/packs/index.js +1 -0
  14. package/dist/runtime/analytics/packs/index.js.map +1 -0
  15. package/dist/runtime/analytics/packs/monetary-measures.d.ts +21 -0
  16. package/dist/runtime/analytics/packs/monetary-measures.js +1 -0
  17. package/dist/runtime/analytics/packs/monetary-measures.js.map +1 -0
  18. package/dist/runtime/analytics/specs.d.ts +49 -0
  19. package/dist/runtime/analytics/specs.js +1 -0
  20. package/dist/runtime/analytics/specs.js.map +1 -0
  21. package/dist/runtime/analytics/types.d.ts +85 -0
  22. package/dist/runtime/analytics/types.js +49 -0
  23. package/dist/runtime/analytics/types.js.map +1 -0
  24. package/dist/runtime/base-classes/activity-entity-repository.d.ts +26 -0
  25. package/dist/runtime/base-classes/activity-entity-repository.js +195 -0
  26. package/dist/runtime/base-classes/activity-entity-repository.js.map +1 -0
  27. package/dist/runtime/base-classes/activity-entity-service.d.ts +39 -0
  28. package/dist/runtime/base-classes/activity-entity-service.js +214 -0
  29. package/dist/runtime/base-classes/activity-entity-service.js.map +1 -0
  30. package/dist/runtime/base-classes/base-read-use-cases.d.ts +68 -0
  31. package/dist/runtime/base-classes/base-read-use-cases.js +32 -0
  32. package/dist/runtime/base-classes/base-read-use-cases.js.map +1 -0
  33. package/dist/runtime/base-classes/base-repository.d.ts +99 -0
  34. package/dist/runtime/base-classes/base-repository.js +160 -0
  35. package/dist/runtime/base-classes/base-repository.js.map +1 -0
  36. package/dist/runtime/base-classes/base-service.d.ts +98 -0
  37. package/dist/runtime/base-classes/base-service.js +186 -0
  38. package/dist/runtime/base-classes/base-service.js.map +1 -0
  39. package/dist/runtime/base-classes/index.d.ts +18 -0
  40. package/dist/runtime/base-classes/index.js +617 -0
  41. package/dist/runtime/base-classes/index.js.map +1 -0
  42. package/dist/runtime/base-classes/knowledge-entity-repository.d.ts +17 -0
  43. package/dist/runtime/base-classes/knowledge-entity-repository.js +166 -0
  44. package/dist/runtime/base-classes/knowledge-entity-repository.js.map +1 -0
  45. package/dist/runtime/base-classes/knowledge-entity-service.d.ts +15 -0
  46. package/dist/runtime/base-classes/knowledge-entity-service.js +192 -0
  47. package/dist/runtime/base-classes/knowledge-entity-service.js.map +1 -0
  48. package/dist/runtime/base-classes/lifecycle-events.d.ts +49 -0
  49. package/dist/runtime/base-classes/lifecycle-events.js +76 -0
  50. package/dist/runtime/base-classes/lifecycle-events.js.map +1 -0
  51. package/dist/runtime/base-classes/metadata-entity-repository.d.ts +27 -0
  52. package/dist/runtime/base-classes/metadata-entity-repository.js +212 -0
  53. package/dist/runtime/base-classes/metadata-entity-repository.js.map +1 -0
  54. package/dist/runtime/base-classes/metadata-entity-service.d.ts +39 -0
  55. package/dist/runtime/base-classes/metadata-entity-service.js +214 -0
  56. package/dist/runtime/base-classes/metadata-entity-service.js.map +1 -0
  57. package/dist/runtime/base-classes/synced-entity-repository.d.ts +32 -0
  58. package/dist/runtime/base-classes/synced-entity-repository.js +203 -0
  59. package/dist/runtime/base-classes/synced-entity-repository.js.map +1 -0
  60. package/dist/runtime/base-classes/synced-entity-service.d.ts +41 -0
  61. package/dist/runtime/base-classes/synced-entity-service.js +215 -0
  62. package/dist/runtime/base-classes/synced-entity-service.js.map +1 -0
  63. package/dist/runtime/base-classes/with-analytics.d.ts +18 -0
  64. package/dist/runtime/base-classes/with-analytics.js +11 -0
  65. package/dist/runtime/base-classes/with-analytics.js.map +1 -0
  66. package/dist/runtime/constants/tokens.d.ts +29 -0
  67. package/dist/runtime/constants/tokens.js +8 -0
  68. package/dist/runtime/constants/tokens.js.map +1 -0
  69. package/dist/runtime/subsystems/analytics/analytics-query.protocol.d.ts +30 -0
  70. package/dist/runtime/subsystems/analytics/analytics-query.protocol.js +1 -0
  71. package/dist/runtime/subsystems/analytics/analytics-query.protocol.js.map +1 -0
  72. package/dist/runtime/subsystems/analytics/analytics.module.d.ts +34 -0
  73. package/dist/runtime/subsystems/analytics/analytics.module.js +117 -0
  74. package/dist/runtime/subsystems/analytics/analytics.module.js.map +1 -0
  75. package/dist/runtime/subsystems/analytics/analytics.tokens.d.ts +24 -0
  76. package/dist/runtime/subsystems/analytics/analytics.tokens.js +10 -0
  77. package/dist/runtime/subsystems/analytics/analytics.tokens.js.map +1 -0
  78. package/dist/runtime/subsystems/analytics/cube-backend.d.ts +28 -0
  79. package/dist/runtime/subsystems/analytics/cube-backend.js +71 -0
  80. package/dist/runtime/subsystems/analytics/cube-backend.js.map +1 -0
  81. package/dist/runtime/subsystems/analytics/index.d.ts +6 -0
  82. package/dist/runtime/subsystems/analytics/index.js +122 -0
  83. package/dist/runtime/subsystems/analytics/index.js.map +1 -0
  84. package/dist/runtime/subsystems/analytics/noop-backend.d.ts +7 -0
  85. package/dist/runtime/subsystems/analytics/noop-backend.js +25 -0
  86. package/dist/runtime/subsystems/analytics/noop-backend.js.map +1 -0
  87. package/dist/runtime/subsystems/cache/cache.drizzle-backend.d.ts +43 -0
  88. package/dist/runtime/subsystems/cache/cache.drizzle-backend.js +133 -0
  89. package/dist/runtime/subsystems/cache/cache.drizzle-backend.js.map +1 -0
  90. package/dist/runtime/subsystems/cache/cache.memory-backend.d.ts +21 -0
  91. package/dist/runtime/subsystems/cache/cache.memory-backend.js +100 -0
  92. package/dist/runtime/subsystems/cache/cache.memory-backend.js.map +1 -0
  93. package/dist/runtime/subsystems/cache/cache.module.d.ts +37 -0
  94. package/dist/runtime/subsystems/cache/cache.module.js +272 -0
  95. package/dist/runtime/subsystems/cache/cache.module.js.map +1 -0
  96. package/dist/runtime/subsystems/cache/cache.protocol.d.ts +42 -0
  97. package/dist/runtime/subsystems/cache/cache.protocol.js +1 -0
  98. package/dist/runtime/subsystems/cache/cache.protocol.js.map +1 -0
  99. package/dist/runtime/subsystems/cache/cache.schema.d.ts +64 -0
  100. package/dist/runtime/subsystems/cache/cache.schema.js +18 -0
  101. package/dist/runtime/subsystems/cache/cache.schema.js.map +1 -0
  102. package/dist/runtime/subsystems/cache/cache.tokens.d.ts +18 -0
  103. package/dist/runtime/subsystems/cache/cache.tokens.js +8 -0
  104. package/dist/runtime/subsystems/cache/cache.tokens.js.map +1 -0
  105. package/dist/runtime/subsystems/cache/index.d.ts +11 -0
  106. package/dist/runtime/subsystems/cache/index.js +277 -0
  107. package/dist/runtime/subsystems/cache/index.js.map +1 -0
  108. package/dist/runtime/subsystems/events/domain-events.schema.d.ts +187 -0
  109. package/dist/runtime/subsystems/events/domain-events.schema.js +32 -0
  110. package/dist/runtime/subsystems/events/domain-events.schema.js.map +1 -0
  111. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.d.ts +38 -0
  112. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +199 -0
  113. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -0
  114. package/dist/runtime/subsystems/events/event-bus.memory-backend.d.ts +18 -0
  115. package/dist/runtime/subsystems/events/event-bus.memory-backend.js +71 -0
  116. package/dist/runtime/subsystems/events/event-bus.memory-backend.js.map +1 -0
  117. package/dist/runtime/subsystems/events/event-bus.protocol.d.ts +52 -0
  118. package/dist/runtime/subsystems/events/event-bus.protocol.js +1 -0
  119. package/dist/runtime/subsystems/events/event-bus.protocol.js.map +1 -0
  120. package/dist/runtime/subsystems/events/event-bus.redis-backend.d.ts +95 -0
  121. package/dist/runtime/subsystems/events/event-bus.redis-backend.js +229 -0
  122. package/dist/runtime/subsystems/events/event-bus.redis-backend.js.map +1 -0
  123. package/dist/runtime/subsystems/events/events.module.d.ts +46 -0
  124. package/dist/runtime/subsystems/events/events.module.js +531 -0
  125. package/dist/runtime/subsystems/events/events.module.js.map +1 -0
  126. package/dist/runtime/subsystems/events/events.tokens.d.ts +19 -0
  127. package/dist/runtime/subsystems/events/events.tokens.js +8 -0
  128. package/dist/runtime/subsystems/events/events.tokens.js.map +1 -0
  129. package/dist/runtime/subsystems/events/index.d.ts +12 -0
  130. package/dist/runtime/subsystems/events/index.js +536 -0
  131. package/dist/runtime/subsystems/events/index.js.map +1 -0
  132. package/dist/runtime/subsystems/index.d.ts +24 -0
  133. package/dist/runtime/subsystems/index.js +1643 -0
  134. package/dist/runtime/subsystems/index.js.map +1 -0
  135. package/dist/runtime/subsystems/jobs/index.d.ts +14 -0
  136. package/dist/runtime/subsystems/jobs/index.js +680 -0
  137. package/dist/runtime/subsystems/jobs/index.js.map +1 -0
  138. package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.d.ts +54 -0
  139. package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.js +186 -0
  140. package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.js.map +1 -0
  141. package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.d.ts +38 -0
  142. package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.js +228 -0
  143. package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.js.map +1 -0
  144. package/dist/runtime/subsystems/jobs/job-queue.memory-backend.d.ts +12 -0
  145. package/dist/runtime/subsystems/jobs/job-queue.memory-backend.js +44 -0
  146. package/dist/runtime/subsystems/jobs/job-queue.memory-backend.js.map +1 -0
  147. package/dist/runtime/subsystems/jobs/job-queue.protocol.d.ts +48 -0
  148. package/dist/runtime/subsystems/jobs/job-queue.protocol.js +1 -0
  149. package/dist/runtime/subsystems/jobs/job-queue.protocol.js.map +1 -0
  150. package/dist/runtime/subsystems/jobs/job-queue.redis-backend.d.ts +46 -0
  151. package/dist/runtime/subsystems/jobs/job-queue.redis-backend.js +187 -0
  152. package/dist/runtime/subsystems/jobs/job-queue.redis-backend.js.map +1 -0
  153. package/dist/runtime/subsystems/jobs/job-queue.schema.d.ts +237 -0
  154. package/dist/runtime/subsystems/jobs/job-queue.schema.js +44 -0
  155. package/dist/runtime/subsystems/jobs/job-queue.schema.js.map +1 -0
  156. package/dist/runtime/subsystems/jobs/jobs.module.d.ts +18 -0
  157. package/dist/runtime/subsystems/jobs/jobs.module.js +676 -0
  158. package/dist/runtime/subsystems/jobs/jobs.module.js.map +1 -0
  159. package/dist/runtime/subsystems/jobs/jobs.tokens.d.ts +13 -0
  160. package/dist/runtime/subsystems/jobs/jobs.tokens.js +8 -0
  161. package/dist/runtime/subsystems/jobs/jobs.tokens.js.map +1 -0
  162. package/dist/runtime/subsystems/storage/index.d.ts +6 -0
  163. package/dist/runtime/subsystems/storage/index.js +204 -0
  164. package/dist/runtime/subsystems/storage/index.js.map +1 -0
  165. package/dist/runtime/subsystems/storage/storage.local-backend.d.ts +18 -0
  166. package/dist/runtime/subsystems/storage/storage.local-backend.js +108 -0
  167. package/dist/runtime/subsystems/storage/storage.local-backend.js.map +1 -0
  168. package/dist/runtime/subsystems/storage/storage.memory-backend.d.ts +28 -0
  169. package/dist/runtime/subsystems/storage/storage.memory-backend.js +72 -0
  170. package/dist/runtime/subsystems/storage/storage.memory-backend.js.map +1 -0
  171. package/dist/runtime/subsystems/storage/storage.module.d.ts +40 -0
  172. package/dist/runtime/subsystems/storage/storage.module.js +201 -0
  173. package/dist/runtime/subsystems/storage/storage.module.js.map +1 -0
  174. package/dist/runtime/subsystems/storage/storage.protocol.d.ts +69 -0
  175. package/dist/runtime/subsystems/storage/storage.protocol.js +1 -0
  176. package/dist/runtime/subsystems/storage/storage.protocol.js.map +1 -0
  177. package/dist/runtime/subsystems/storage/storage.tokens.d.ts +11 -0
  178. package/dist/runtime/subsystems/storage/storage.tokens.js +6 -0
  179. package/dist/runtime/subsystems/storage/storage.tokens.js.map +1 -0
  180. package/dist/runtime/subsystems/storage/storage.utils.d.ts +9 -0
  181. package/dist/runtime/subsystems/storage/storage.utils.js +18 -0
  182. package/dist/runtime/subsystems/storage/storage.utils.js.map +1 -0
  183. package/dist/runtime/types/drizzle.d.ts +17 -0
  184. package/dist/runtime/types/drizzle.js +1 -0
  185. package/dist/runtime/types/drizzle.js.map +1 -0
  186. package/dist/src/cli/index.d.ts +1 -0
  187. package/dist/src/cli/index.js +7365 -0
  188. package/dist/src/cli/index.js.map +1 -0
  189. package/dist/src/index.d.ts +2384 -0
  190. package/dist/src/index.js +2198 -0
  191. package/dist/src/index.js.map +1 -0
  192. package/package.json +114 -0
  193. package/templates/broadcast/new/backend-interface.ejs.t +47 -0
  194. package/templates/broadcast/new/bridge-listener.ejs.t +67 -0
  195. package/templates/broadcast/new/channel.ejs.t +77 -0
  196. package/templates/broadcast/new/index.ejs.t +21 -0
  197. package/templates/broadcast/new/memory-backend.ejs.t +87 -0
  198. package/templates/broadcast/new/module.ejs.t +57 -0
  199. package/templates/broadcast/new/prompt.js +268 -0
  200. package/templates/broadcast/new/websocket-backend.ejs.t +259 -0
  201. package/templates/entity/new/backend/application/commands/create.ejs.t +55 -0
  202. package/templates/entity/new/backend/application/commands/delete.ejs.t +45 -0
  203. package/templates/entity/new/backend/application/commands/grouped-index.ejs.t +149 -0
  204. package/templates/entity/new/backend/application/commands/index.ejs.t +15 -0
  205. package/templates/entity/new/backend/application/commands/update.ejs.t +58 -0
  206. package/templates/entity/new/backend/application/queries/declarative-queries.ejs.t +36 -0
  207. package/templates/entity/new/backend/application/queries/get-by-id.ejs.t +42 -0
  208. package/templates/entity/new/backend/application/queries/grouped-index.ejs.t +81 -0
  209. package/templates/entity/new/backend/application/queries/index.ejs.t +14 -0
  210. package/templates/entity/new/backend/application/queries/list.ejs.t +36 -0
  211. package/templates/entity/new/backend/application/schemas/_inject-index.ejs.t +7 -0
  212. package/templates/entity/new/backend/application/schemas/dto.ejs.t +45 -0
  213. package/templates/entity/new/backend/database/_inject-index.ejs.t +7 -0
  214. package/templates/entity/new/backend/database/electric-migration.ejs.t +21 -0
  215. package/templates/entity/new/backend/database/repository.ejs.t +450 -0
  216. package/templates/entity/new/backend/database/schema.ejs.t +248 -0
  217. package/templates/entity/new/backend/domain/_inject-index.ejs.t +12 -0
  218. package/templates/entity/new/backend/domain/entity.ejs.t +108 -0
  219. package/templates/entity/new/backend/domain/grouped-index.ejs.t +163 -0
  220. package/templates/entity/new/backend/domain/index.ejs.t +15 -0
  221. package/templates/entity/new/backend/domain/repository-interface.ejs.t +71 -0
  222. package/templates/entity/new/backend/modules/core/_ensure-anchor-tokens.ejs.t +10 -0
  223. package/templates/entity/new/backend/modules/core/_inject-token.ejs.t +7 -0
  224. package/templates/entity/new/backend/modules/core/module.ejs.t +67 -0
  225. package/templates/entity/new/backend/modules/trpc/module.ejs.t +67 -0
  226. package/templates/entity/new/backend/presentation/controller.ejs.t +201 -0
  227. package/templates/entity/new/clean-lite-ps/controller.ejs.t +37 -0
  228. package/templates/entity/new/clean-lite-ps/dto/create.ejs.t +17 -0
  229. package/templates/entity/new/clean-lite-ps/dto/output.ejs.t +25 -0
  230. package/templates/entity/new/clean-lite-ps/dto/update.ejs.t +11 -0
  231. package/templates/entity/new/clean-lite-ps/entity.ejs.t +52 -0
  232. package/templates/entity/new/clean-lite-ps/index.ejs.t +20 -0
  233. package/templates/entity/new/clean-lite-ps/module.ejs.t +43 -0
  234. package/templates/entity/new/clean-lite-ps/prompt-extension.js +617 -0
  235. package/templates/entity/new/clean-lite-ps/repository.ejs.t +62 -0
  236. package/templates/entity/new/clean-lite-ps/service.ejs.t +34 -0
  237. package/templates/entity/new/clean-lite-ps/use-cases/declarative-queries.ejs.t +34 -0
  238. package/templates/entity/new/clean-lite-ps/use-cases/find-by-id.ejs.t +16 -0
  239. package/templates/entity/new/clean-lite-ps/use-cases/list.ejs.t +16 -0
  240. package/templates/entity/new/frontend/_inject-entities-entry.ejs.t +7 -0
  241. package/templates/entity/new/frontend/_inject-entities-import.ejs.t +7 -0
  242. package/templates/entity/new/frontend/collections/_ensure-anchor-collections.ejs.t +10 -0
  243. package/templates/entity/new/frontend/collections/_inject-index.ejs.t +9 -0
  244. package/templates/entity/new/frontend/collections/_inject-schema-import.ejs.t +9 -0
  245. package/templates/entity/new/frontend/collections/collection.ejs.t +61 -0
  246. package/templates/entity/new/frontend/collections/collections-base.ejs.t +24 -0
  247. package/templates/entity/new/frontend/entity/collection.ejs.t +172 -0
  248. package/templates/entity/new/frontend/entity/combined.ejs.t +474 -0
  249. package/templates/entity/new/frontend/entity/fields.ejs.t +104 -0
  250. package/templates/entity/new/frontend/entity/hooks.ejs.t +73 -0
  251. package/templates/entity/new/frontend/entity/index.ejs.t +21 -0
  252. package/templates/entity/new/frontend/entity/mutation-hooks.ejs.t +84 -0
  253. package/templates/entity/new/frontend/entity/mutations.ejs.t +38 -0
  254. package/templates/entity/new/frontend/entity/types.ejs.t +59 -0
  255. package/templates/entity/new/frontend/generated/_inject-index-export.ejs.t +7 -0
  256. package/templates/entity/new/frontend/generated/_inject-index-import.ejs.t +7 -0
  257. package/templates/entity/new/frontend/generated/_inject-index-registry.ejs.t +7 -0
  258. package/templates/entity/new/frontend/store/_inject-collection-import.ejs.t +9 -0
  259. package/templates/entity/new/frontend/store/_inject-collections.ejs.t +9 -0
  260. package/templates/entity/new/frontend/store/_inject-entity.ejs.t +9 -0
  261. package/templates/entity/new/frontend/store/_inject-import.ejs.t +9 -0
  262. package/templates/entity/new/frontend/store/_inject-lookups.ejs.t +9 -0
  263. package/templates/entity/new/frontend/store/_inject-resolve.ejs.t +10 -0
  264. package/templates/entity/new/frontend/store/hooks.ejs.t +72 -0
  265. package/templates/entity/new/frontend/unified-entity.ejs.t +28 -0
  266. package/templates/entity/new/prompt.js +1421 -0
  267. package/templates/relationship/new/controller.ejs.t +36 -0
  268. package/templates/relationship/new/dto/create.ejs.t +41 -0
  269. package/templates/relationship/new/dto/output.ejs.t +44 -0
  270. package/templates/relationship/new/dto/update.ejs.t +10 -0
  271. package/templates/relationship/new/entity.ejs.t +98 -0
  272. package/templates/relationship/new/index.ejs.t +19 -0
  273. package/templates/relationship/new/module.ejs.t +35 -0
  274. package/templates/relationship/new/prompt.js +682 -0
  275. package/templates/relationship/new/repository.ejs.t +54 -0
  276. package/templates/relationship/new/service.ejs.t +31 -0
  277. package/templates/relationship/new/use-cases/declarative-queries.ejs.t +34 -0
  278. package/templates/relationship/new/use-cases/find-by-id.ejs.t +16 -0
  279. package/templates/relationship/new/use-cases/list.ejs.t +16 -0
@@ -0,0 +1,84 @@
1
+ ---
2
+ to: "<%= generate.structure === 'entity-first' ? `${locations.frontendGenerated.path}/${generate.fileNaming === 'plural' ? plural : name}/mutation-hooks.ts` : generate.structure === 'concern-first' ? `${locations.frontendGenerated.path}/mutation-hooks/${generate.fileNaming === 'plural' ? plural : name}.ts` : '' %>"
3
+ skip_if: <%= !frontendEnabled || (generate.structure === 'monolithic' || !generate.mutations || !(exposeTrpc || exposeRepository)) %>
4
+ force: true
5
+ ---
6
+ /**
7
+ * <%= className %> Mutation Hooks
8
+ * Generated by entity codegen - do not edit directly
9
+ *
10
+ * React hooks wrapping mutation functions with error state management
11
+ */
12
+
13
+ import { useState, useCallback } from 'react';
14
+ <%
15
+ // File name for imports depends on fileNaming config
16
+ const fileName = generate.fileNaming === 'plural' ? plural : name;
17
+ -%>
18
+ <% if (generate.structure === 'entity-first') { -%>
19
+ import { insert<%= className %>, update<%= className %>, delete<%= className %> } from './mutations';
20
+ import type { <%= className %> } from './types';
21
+ <% } else if (generate.structure === 'concern-first') { -%>
22
+ import { insert<%= className %>, update<%= className %>, delete<%= className %> } from '../mutations/<%= fileName %>';
23
+ import type { <%= className %> } from '../types/<%= fileName %>';
24
+ <% } -%>
25
+
26
+ type MutationHookResult<TFn extends (...args: any[]) => any> = {
27
+ mutate: TFn;
28
+ error: Error | null;
29
+ clearError: () => void;
30
+ };
31
+
32
+ export function useCreate<%= className %>(): MutationHookResult<typeof insert<%= className %>> {
33
+ const [error, setError] = useState<Error | null>(null);
34
+
35
+ const mutate = useCallback<typeof insert<%= className %>>((data) => {
36
+ try {
37
+ insert<%= className %>(data);
38
+ setError(null);
39
+ } catch (err) {
40
+ const error = err instanceof Error ? err : new Error(String(err));
41
+ setError(error);
42
+ throw error;
43
+ }
44
+ }, []);
45
+
46
+ const clearError = useCallback(() => setError(null), []);
47
+ return { mutate, error, clearError };
48
+ }
49
+
50
+ export function useUpdate<%= className %>(): MutationHookResult<typeof update<%= className %>> {
51
+ const [error, setError] = useState<Error | null>(null);
52
+
53
+ const mutate = useCallback<typeof update<%= className %>>((id, fn) => {
54
+ try {
55
+ update<%= className %>(id, fn);
56
+ setError(null);
57
+ } catch (err) {
58
+ const error = err instanceof Error ? err : new Error(String(err));
59
+ setError(error);
60
+ throw error;
61
+ }
62
+ }, []);
63
+
64
+ const clearError = useCallback(() => setError(null), []);
65
+ return { mutate, error, clearError };
66
+ }
67
+
68
+ export function useDelete<%= className %>(): MutationHookResult<typeof delete<%= className %>> {
69
+ const [error, setError] = useState<Error | null>(null);
70
+
71
+ const mutate = useCallback<typeof delete<%= className %>>((id) => {
72
+ try {
73
+ delete<%= className %>(id);
74
+ setError(null);
75
+ } catch (err) {
76
+ const error = err instanceof Error ? err : new Error(String(err));
77
+ setError(error);
78
+ throw error;
79
+ }
80
+ }, []);
81
+
82
+ const clearError = useCallback(() => setError(null), []);
83
+ return { mutate, error, clearError };
84
+ }
@@ -0,0 +1,38 @@
1
+ ---
2
+ to: "<%= generate.structure === 'entity-first' ? `${locations.frontendGenerated.path}/${name}/mutations.ts` : generate.structure === 'concern-first' ? `${locations.frontendGenerated.path}/mutations/${name}.ts` : '' %>"
3
+ skip_if: <%= !frontendEnabled || (generate.structure === 'monolithic' || !generate.mutations || !(exposeTrpc || exposeRepository)) %>
4
+ force: true
5
+ ---
6
+ /**
7
+ * <%= className %> Mutations
8
+ * Generated by entity codegen - do not edit directly
9
+ *
10
+ * Optimistic update functions for <%= className %> entity
11
+ */
12
+
13
+ <% if (generate.structure === 'entity-first') { -%>
14
+ import { <%= camelName %>Collection } from './collection';
15
+ import type { <%= className %> } from './types';
16
+ <% } else if (generate.structure === 'concern-first') { -%>
17
+ import { <%= camelName %>Collection } from '../collections/<%= name %>';
18
+ import type { <%= className %> } from '../types/<%= name %>';
19
+ <% } -%>
20
+
21
+ export function insert<%= className %>(data: Omit<<%= className %>, 'id'<% if (hasTimestamps) { %> | 'createdAt' | 'updatedAt'<% } %>>) {
22
+ return <%= camelName %>Collection.insert({
23
+ id: crypto.randomUUID(),
24
+ <% if (hasTimestamps) { -%>
25
+ createdAt: new Date(),
26
+ updatedAt: new Date(),
27
+ <% } -%>
28
+ ...data,
29
+ } as <%= className %>);
30
+ }
31
+
32
+ export function update<%= className %>(id: string, fn: (draft: <%= className %>) => void) {
33
+ return <%= camelName %>Collection.update(id, fn);
34
+ }
35
+
36
+ export function delete<%= className %>(id: string) {
37
+ return <%= camelName %>Collection.delete(id);
38
+ }
@@ -0,0 +1,59 @@
1
+ ---
2
+ to: "<%= generate.structure === 'entity-first' ? `${locations.frontendGenerated.path}/${generate.fileNaming === 'plural' ? plural : name}/types.ts` : generate.structure === 'concern-first' ? `${locations.frontendGenerated.path}/types/${generate.fileNaming === 'plural' ? plural : name}.ts` : '' %>"
3
+ skip_if: <%= !frontendEnabled || (generate.structure === 'monolithic') %>
4
+ force: true
5
+ ---
6
+ /**
7
+ * <%= className %> Types
8
+ * Generated by entity codegen - do not edit directly
9
+ *
10
+ * Type definitions for <%= className %> entity with resolved relations
11
+ */
12
+
13
+ <%
14
+ // Type import: depends on typeNaming config
15
+ // 'entity' = source exports OpportunityEntity, 'plain' = source exports Opportunity
16
+ const importedTypeName = generate.typeNaming === 'plain' ? className : className + 'Entity';
17
+ // Collect unique belongs_to targets for imports (FK resolution)
18
+ // Only import if fkResolution is enabled (default: true)
19
+ const importedEntities = new Set();
20
+ if (generate.fkResolution !== false) {
21
+ existingBelongsTo.forEach((rel) => {
22
+ if (rel.target !== name) {
23
+ importedEntities.add(rel.target);
24
+ }
25
+ });
26
+ }
27
+ -%>
28
+ import type { <%= importedTypeName %> } from '<%= locations.dbEntities.import %><% if (!locations.dbEntities.barrelExport) { %>/<%= name %><% } %>';
29
+ <% if (importedEntities.size > 0) { -%>
30
+
31
+ // Import related entity types for FK resolution
32
+ <% importedEntities.forEach((target) => {
33
+ const targetClass = target.charAt(0).toUpperCase() + target.slice(1).replace(/_([a-z])/g, (_, c) => c.toUpperCase());
34
+ -%>
35
+ import type { <%= generate.typeNaming === 'plain' ? targetClass : targetClass + 'Entity' %> } from '<%= locations.dbEntities.import %><% if (!locations.dbEntities.barrelExport) { %>/<%= target %><% } %>';
36
+ <% }); -%>
37
+ <% } -%>
38
+
39
+ /** Base entity from database */
40
+ <% if (generate.typeNaming === 'plain') { -%>
41
+ export type { <%= className %> };
42
+ <% } else { -%>
43
+ export type <%= className %> = <%= importedTypeName %>;
44
+ <% } -%>
45
+ <% if (existingBelongsTo.length > 0 && generate.fkResolution !== false) { -%>
46
+
47
+ /** Entity with resolved FK relations (only includes relations with existing targets) */
48
+ export interface <%= className %>Resolved extends <%= className %> {
49
+ <% existingBelongsTo.forEach((rel) => { -%>
50
+ <% // Use local type for self-referential, imported type for others -%>
51
+ <% const relTypeName = rel.target === name ? className : (generate.typeNaming === 'plain' ? rel.targetClass : rel.targetClass + 'Entity'); -%>
52
+ <%= rel.name %>?: <%= relTypeName %>;
53
+ <% }); -%>
54
+ }
55
+ <% } else { -%>
56
+
57
+ /** Entity type (no FK relations to resolve) */
58
+ export type <%= className %>Resolved = <%= className %>;
59
+ <% } -%>
@@ -0,0 +1,7 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? `${locations.frontendGenerated.path}/index.ts` : '' %>"
3
+ inject: true
4
+ skip_if: "from './<%= name %>'"
5
+ after: "// Entity exports"
6
+ ---
7
+ export * from './<%= name %>';
@@ -0,0 +1,7 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? `${locations.frontendGenerated.path}/index.ts` : '' %>"
3
+ inject: true
4
+ skip_if: "import { <%= camelName %> }"
5
+ after: "// Entity registry"
6
+ ---
7
+ import { <%= camelName %> } from './<%= name %>';
@@ -0,0 +1,7 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? `${locations.frontendGenerated.path}/index.ts` : '' %>"
3
+ inject: true
4
+ skip_if: "<%= camelName %>,"
5
+ after: "// registry-entries"
6
+ ---
7
+ <%= camelName %>,
@@ -0,0 +1,9 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? (generate.hooks ? `${locations.frontendStore.path}/index.ts` : '') : '' %>"
3
+ inject: true
4
+ after: "// Collection imports"
5
+ skip_if: "from '<%= locations.frontendCollections.import %>/collections'"
6
+ ---
7
+ <% if (generate.hooks) { -%>
8
+ import { <%= collectionVarName %> } from '<%= locations.frontendCollections.import %>/collections';
9
+ <% } -%>
@@ -0,0 +1,9 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? (generate.hooks ? `${locations.frontendStore.path}/index.ts` : '') : '' %>"
3
+ inject: true
4
+ after: "collections: \\{"
5
+ skip_if: "<%= plural %>: <%= collectionVarName %>[^\\.]"
6
+ ---
7
+ <% if (generate.hooks) { -%>
8
+ <%= plural %>: <%= collectionVarName %>,
9
+ <% } -%>
@@ -0,0 +1,9 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? (generate.hooks ? `${locations.frontendStore.path}/index.ts` : '') : '' %>"
3
+ inject: true
4
+ after: "entities: \\{"
5
+ skip_if: "<%= plural %>: <%= camelName %>Hooks"
6
+ ---
7
+ <% if (generate.hooks) { -%>
8
+ <%= plural %>: <%= camelName %>Hooks,
9
+ <% } -%>
@@ -0,0 +1,9 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? (generate.hooks ? `${locations.frontendStore.path}/index.ts` : '') : '' %>"
3
+ inject: true
4
+ after: "// Entity hooks"
5
+ skip_if: "from './entities/<%= name %>'"
6
+ ---
7
+ <% if (generate.hooks) { -%>
8
+ import { <%= camelName %>Hooks } from './entities/<%= name %>';
9
+ <% } -%>
@@ -0,0 +1,9 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? (generate.hooks ? `${locations.frontendStore.path}/index.ts` : '') : '' %>"
3
+ inject: true
4
+ after: "// Lookup entries"
5
+ skip_if: "<%= plural %>: <%= collectionVarName %>\\.state"
6
+ ---
7
+ <% if (generate.hooks) { -%>
8
+ <%= plural %>: <%= collectionVarName %>.state,
9
+ <% } -%>
@@ -0,0 +1,10 @@
1
+ ---
2
+ to: "<%= frontendEnabled ? (generate.hooks ? `${locations.frontendStore.path}/index.ts` : '') : '' %>"
3
+ inject: true
4
+ after: "resolve: \\{"
5
+ skip_if: "<%= singularCamelName %>:"
6
+ ---
7
+ <% if (generate.hooks) { -%>
8
+ <%= singularCamelName %>: (id: string | null | undefined) =>
9
+ id ? <%= collectionVarName %>.get(id) : undefined,
10
+ <% } -%>
@@ -0,0 +1,72 @@
1
+ ---
2
+ to: <%= locations.frontendStoreEntities.path %>/<%= name %>.ts
3
+ skip_if: <%= !frontendEnabled || (!generate.hooks) %>
4
+ force: true
5
+ ---
6
+ /**
7
+ * <%= className %> Entity Hooks
8
+ * Generated by entity codegen - do not edit directly
9
+ *
10
+ * Provides query and mutation hooks for <%= className %> entity.
11
+ */
12
+
13
+ import { useLiveQuery } from '@tanstack/react-db';
14
+ import { eq } from '@tanstack/react-db';
15
+ import { <%= camelName %>Collection } from '<%= locations.frontendCollections.import %>/collections';
16
+ <%
17
+ const entityTypeName = generate.typeNaming === 'plain' ? className : className + 'Entity';
18
+ -%>
19
+ import type { <%= entityTypeName %> } from '<%= locations.dbEntities.import %>/<%= name %>';
20
+
21
+ /**
22
+ * Hook to get all <%= plural %>
23
+ */
24
+ export function use<%= className %>List() {
25
+ return useLiveQuery((q) => q.from({ <%= camelName %>Collection }), []);
26
+ }
27
+
28
+ /**
29
+ * Hook to get a single <%= camelName %> by ID
30
+ */
31
+ export function use<%= className %>ById(id: string | undefined) {
32
+ return useLiveQuery(
33
+ (q) => {
34
+ if (!id) return undefined;
35
+ return q
36
+ .from({ <%= camelName %>Collection })
37
+ .where(({ <%= camelName %>Collection }) => eq(<%= camelName %>Collection.id, id));
38
+ },
39
+ [id],
40
+ );
41
+ }
42
+
43
+ /**
44
+ * Mutation functions for <%= className %>
45
+ */
46
+ export const <%= camelName %>Mutations = {
47
+ insert: (data: Omit<<%= entityTypeName %>, 'id' | 'createdAt' | 'updatedAt'> & { id?: string }) => {
48
+ return <%= camelName %>Collection.insert({
49
+ id: data.id ?? crypto.randomUUID(),
50
+ ...data,
51
+ createdAt: new Date(),
52
+ updatedAt: new Date(),
53
+ } as <%= entityTypeName %>);
54
+ },
55
+
56
+ update: (id: string, updater: (draft: <%= entityTypeName %>) => void) => {
57
+ return <%= camelName %>Collection.update(id, updater);
58
+ },
59
+
60
+ delete: (id: string) => {
61
+ return <%= camelName %>Collection.delete(id);
62
+ },
63
+ };
64
+
65
+ /**
66
+ * <%= className %> hooks bundle for store
67
+ */
68
+ export const <%= camelName %>Hooks = {
69
+ useList: use<%= className %>List,
70
+ useById: use<%= className %>ById,
71
+ ...<%=camelName %>Mutations,
72
+ };
@@ -0,0 +1,28 @@
1
+ ---
2
+ to: <%= locations.frontendEntities.path %>/<%= name %>.ts
3
+ skip_if: <%= !frontendEnabled %>
4
+ force: true
5
+ ---
6
+ /**
7
+ * <%= className %> - Unified Entity API
8
+ *
9
+ * AUTO-GENERATED by entity codegen - do not edit directly.
10
+ * Combines hooks, metadata, and collection into single interface.
11
+ */
12
+
13
+ import { createUnifiedEntity } from './create-unified-entity';
14
+ import { <%= camelName %>Hooks } from '../store/entities/<%= name %>';
15
+ import { <%= camelName %>Metadata } from '<%= locations.frontendEntityMetadata.import %>';
16
+ import { <%= camelName %>Collection } from '<%= locations.frontendCollections.import %>/collections';
17
+ import { store } from '../store';
18
+ <%
19
+ const entityTypeName = generate.typeNaming === 'plain' ? className : className + 'Entity';
20
+ -%>
21
+ import type { <%= entityTypeName %> } from '<%= locations.dbEntities.import %>/<%= name %>';
22
+
23
+ export const <%= plural %> = createUnifiedEntity<<%= entityTypeName %>>({
24
+ hooks: <%= camelName %>Hooks,
25
+ metadata: <%= camelName %>Metadata,
26
+ collection: <%= camelName %>Collection,
27
+ resolve: store.resolve.<%= camelName %>,
28
+ });