@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.
- package/CHANGELOG.md +67 -0
- package/README.md +214 -0
- package/dist/runtime/analytics/index.d.ts +6 -0
- package/dist/runtime/analytics/index.js +49 -0
- package/dist/runtime/analytics/index.js.map +1 -0
- package/dist/runtime/analytics/metrics.d.ts +75 -0
- package/dist/runtime/analytics/metrics.js +1 -0
- package/dist/runtime/analytics/metrics.js.map +1 -0
- package/dist/runtime/analytics/packs/crm-entity-measures.d.ts +21 -0
- package/dist/runtime/analytics/packs/crm-entity-measures.js +1 -0
- package/dist/runtime/analytics/packs/crm-entity-measures.js.map +1 -0
- package/dist/runtime/analytics/packs/index.d.ts +3 -0
- package/dist/runtime/analytics/packs/index.js +1 -0
- package/dist/runtime/analytics/packs/index.js.map +1 -0
- package/dist/runtime/analytics/packs/monetary-measures.d.ts +21 -0
- package/dist/runtime/analytics/packs/monetary-measures.js +1 -0
- package/dist/runtime/analytics/packs/monetary-measures.js.map +1 -0
- package/dist/runtime/analytics/specs.d.ts +49 -0
- package/dist/runtime/analytics/specs.js +1 -0
- package/dist/runtime/analytics/specs.js.map +1 -0
- package/dist/runtime/analytics/types.d.ts +85 -0
- package/dist/runtime/analytics/types.js +49 -0
- package/dist/runtime/analytics/types.js.map +1 -0
- package/dist/runtime/base-classes/activity-entity-repository.d.ts +26 -0
- package/dist/runtime/base-classes/activity-entity-repository.js +195 -0
- package/dist/runtime/base-classes/activity-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/activity-entity-service.d.ts +39 -0
- package/dist/runtime/base-classes/activity-entity-service.js +214 -0
- package/dist/runtime/base-classes/activity-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/base-read-use-cases.d.ts +68 -0
- package/dist/runtime/base-classes/base-read-use-cases.js +32 -0
- package/dist/runtime/base-classes/base-read-use-cases.js.map +1 -0
- package/dist/runtime/base-classes/base-repository.d.ts +99 -0
- package/dist/runtime/base-classes/base-repository.js +160 -0
- package/dist/runtime/base-classes/base-repository.js.map +1 -0
- package/dist/runtime/base-classes/base-service.d.ts +98 -0
- package/dist/runtime/base-classes/base-service.js +186 -0
- package/dist/runtime/base-classes/base-service.js.map +1 -0
- package/dist/runtime/base-classes/index.d.ts +18 -0
- package/dist/runtime/base-classes/index.js +617 -0
- package/dist/runtime/base-classes/index.js.map +1 -0
- package/dist/runtime/base-classes/knowledge-entity-repository.d.ts +17 -0
- package/dist/runtime/base-classes/knowledge-entity-repository.js +166 -0
- package/dist/runtime/base-classes/knowledge-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/knowledge-entity-service.d.ts +15 -0
- package/dist/runtime/base-classes/knowledge-entity-service.js +192 -0
- package/dist/runtime/base-classes/knowledge-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/lifecycle-events.d.ts +49 -0
- package/dist/runtime/base-classes/lifecycle-events.js +76 -0
- package/dist/runtime/base-classes/lifecycle-events.js.map +1 -0
- package/dist/runtime/base-classes/metadata-entity-repository.d.ts +27 -0
- package/dist/runtime/base-classes/metadata-entity-repository.js +212 -0
- package/dist/runtime/base-classes/metadata-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/metadata-entity-service.d.ts +39 -0
- package/dist/runtime/base-classes/metadata-entity-service.js +214 -0
- package/dist/runtime/base-classes/metadata-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/synced-entity-repository.d.ts +32 -0
- package/dist/runtime/base-classes/synced-entity-repository.js +203 -0
- package/dist/runtime/base-classes/synced-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/synced-entity-service.d.ts +41 -0
- package/dist/runtime/base-classes/synced-entity-service.js +215 -0
- package/dist/runtime/base-classes/synced-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/with-analytics.d.ts +18 -0
- package/dist/runtime/base-classes/with-analytics.js +11 -0
- package/dist/runtime/base-classes/with-analytics.js.map +1 -0
- package/dist/runtime/constants/tokens.d.ts +29 -0
- package/dist/runtime/constants/tokens.js +8 -0
- package/dist/runtime/constants/tokens.js.map +1 -0
- package/dist/runtime/subsystems/analytics/analytics-query.protocol.d.ts +30 -0
- package/dist/runtime/subsystems/analytics/analytics-query.protocol.js +1 -0
- package/dist/runtime/subsystems/analytics/analytics-query.protocol.js.map +1 -0
- package/dist/runtime/subsystems/analytics/analytics.module.d.ts +34 -0
- package/dist/runtime/subsystems/analytics/analytics.module.js +117 -0
- package/dist/runtime/subsystems/analytics/analytics.module.js.map +1 -0
- package/dist/runtime/subsystems/analytics/analytics.tokens.d.ts +24 -0
- package/dist/runtime/subsystems/analytics/analytics.tokens.js +10 -0
- package/dist/runtime/subsystems/analytics/analytics.tokens.js.map +1 -0
- package/dist/runtime/subsystems/analytics/cube-backend.d.ts +28 -0
- package/dist/runtime/subsystems/analytics/cube-backend.js +71 -0
- package/dist/runtime/subsystems/analytics/cube-backend.js.map +1 -0
- package/dist/runtime/subsystems/analytics/index.d.ts +6 -0
- package/dist/runtime/subsystems/analytics/index.js +122 -0
- package/dist/runtime/subsystems/analytics/index.js.map +1 -0
- package/dist/runtime/subsystems/analytics/noop-backend.d.ts +7 -0
- package/dist/runtime/subsystems/analytics/noop-backend.js +25 -0
- package/dist/runtime/subsystems/analytics/noop-backend.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.drizzle-backend.d.ts +43 -0
- package/dist/runtime/subsystems/cache/cache.drizzle-backend.js +133 -0
- package/dist/runtime/subsystems/cache/cache.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.memory-backend.d.ts +21 -0
- package/dist/runtime/subsystems/cache/cache.memory-backend.js +100 -0
- package/dist/runtime/subsystems/cache/cache.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.module.d.ts +37 -0
- package/dist/runtime/subsystems/cache/cache.module.js +272 -0
- package/dist/runtime/subsystems/cache/cache.module.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.protocol.d.ts +42 -0
- package/dist/runtime/subsystems/cache/cache.protocol.js +1 -0
- package/dist/runtime/subsystems/cache/cache.protocol.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.schema.d.ts +64 -0
- package/dist/runtime/subsystems/cache/cache.schema.js +18 -0
- package/dist/runtime/subsystems/cache/cache.schema.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.tokens.d.ts +18 -0
- package/dist/runtime/subsystems/cache/cache.tokens.js +8 -0
- package/dist/runtime/subsystems/cache/cache.tokens.js.map +1 -0
- package/dist/runtime/subsystems/cache/index.d.ts +11 -0
- package/dist/runtime/subsystems/cache/index.js +277 -0
- package/dist/runtime/subsystems/cache/index.js.map +1 -0
- package/dist/runtime/subsystems/events/domain-events.schema.d.ts +187 -0
- package/dist/runtime/subsystems/events/domain-events.schema.js +32 -0
- package/dist/runtime/subsystems/events/domain-events.schema.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.d.ts +38 -0
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +199 -0
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.memory-backend.d.ts +18 -0
- package/dist/runtime/subsystems/events/event-bus.memory-backend.js +71 -0
- package/dist/runtime/subsystems/events/event-bus.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.protocol.d.ts +52 -0
- package/dist/runtime/subsystems/events/event-bus.protocol.js +1 -0
- package/dist/runtime/subsystems/events/event-bus.protocol.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.redis-backend.d.ts +95 -0
- package/dist/runtime/subsystems/events/event-bus.redis-backend.js +229 -0
- package/dist/runtime/subsystems/events/event-bus.redis-backend.js.map +1 -0
- package/dist/runtime/subsystems/events/events.module.d.ts +46 -0
- package/dist/runtime/subsystems/events/events.module.js +531 -0
- package/dist/runtime/subsystems/events/events.module.js.map +1 -0
- package/dist/runtime/subsystems/events/events.tokens.d.ts +19 -0
- package/dist/runtime/subsystems/events/events.tokens.js +8 -0
- package/dist/runtime/subsystems/events/events.tokens.js.map +1 -0
- package/dist/runtime/subsystems/events/index.d.ts +12 -0
- package/dist/runtime/subsystems/events/index.js +536 -0
- package/dist/runtime/subsystems/events/index.js.map +1 -0
- package/dist/runtime/subsystems/index.d.ts +24 -0
- package/dist/runtime/subsystems/index.js +1643 -0
- package/dist/runtime/subsystems/index.js.map +1 -0
- package/dist/runtime/subsystems/jobs/index.d.ts +14 -0
- package/dist/runtime/subsystems/jobs/index.js +680 -0
- package/dist/runtime/subsystems/jobs/index.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.d.ts +54 -0
- package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.js +186 -0
- package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.d.ts +38 -0
- package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.js +228 -0
- package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.memory-backend.d.ts +12 -0
- package/dist/runtime/subsystems/jobs/job-queue.memory-backend.js +44 -0
- package/dist/runtime/subsystems/jobs/job-queue.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.protocol.d.ts +48 -0
- package/dist/runtime/subsystems/jobs/job-queue.protocol.js +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.protocol.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.redis-backend.d.ts +46 -0
- package/dist/runtime/subsystems/jobs/job-queue.redis-backend.js +187 -0
- package/dist/runtime/subsystems/jobs/job-queue.redis-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.schema.d.ts +237 -0
- package/dist/runtime/subsystems/jobs/job-queue.schema.js +44 -0
- package/dist/runtime/subsystems/jobs/job-queue.schema.js.map +1 -0
- package/dist/runtime/subsystems/jobs/jobs.module.d.ts +18 -0
- package/dist/runtime/subsystems/jobs/jobs.module.js +676 -0
- package/dist/runtime/subsystems/jobs/jobs.module.js.map +1 -0
- package/dist/runtime/subsystems/jobs/jobs.tokens.d.ts +13 -0
- package/dist/runtime/subsystems/jobs/jobs.tokens.js +8 -0
- package/dist/runtime/subsystems/jobs/jobs.tokens.js.map +1 -0
- package/dist/runtime/subsystems/storage/index.d.ts +6 -0
- package/dist/runtime/subsystems/storage/index.js +204 -0
- package/dist/runtime/subsystems/storage/index.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.local-backend.d.ts +18 -0
- package/dist/runtime/subsystems/storage/storage.local-backend.js +108 -0
- package/dist/runtime/subsystems/storage/storage.local-backend.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.memory-backend.d.ts +28 -0
- package/dist/runtime/subsystems/storage/storage.memory-backend.js +72 -0
- package/dist/runtime/subsystems/storage/storage.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.module.d.ts +40 -0
- package/dist/runtime/subsystems/storage/storage.module.js +201 -0
- package/dist/runtime/subsystems/storage/storage.module.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.protocol.d.ts +69 -0
- package/dist/runtime/subsystems/storage/storage.protocol.js +1 -0
- package/dist/runtime/subsystems/storage/storage.protocol.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.tokens.d.ts +11 -0
- package/dist/runtime/subsystems/storage/storage.tokens.js +6 -0
- package/dist/runtime/subsystems/storage/storage.tokens.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.utils.d.ts +9 -0
- package/dist/runtime/subsystems/storage/storage.utils.js +18 -0
- package/dist/runtime/subsystems/storage/storage.utils.js.map +1 -0
- package/dist/runtime/types/drizzle.d.ts +17 -0
- package/dist/runtime/types/drizzle.js +1 -0
- package/dist/runtime/types/drizzle.js.map +1 -0
- package/dist/src/cli/index.d.ts +1 -0
- package/dist/src/cli/index.js +7365 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/index.d.ts +2384 -0
- package/dist/src/index.js +2198 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +114 -0
- package/templates/broadcast/new/backend-interface.ejs.t +47 -0
- package/templates/broadcast/new/bridge-listener.ejs.t +67 -0
- package/templates/broadcast/new/channel.ejs.t +77 -0
- package/templates/broadcast/new/index.ejs.t +21 -0
- package/templates/broadcast/new/memory-backend.ejs.t +87 -0
- package/templates/broadcast/new/module.ejs.t +57 -0
- package/templates/broadcast/new/prompt.js +268 -0
- package/templates/broadcast/new/websocket-backend.ejs.t +259 -0
- package/templates/entity/new/backend/application/commands/create.ejs.t +55 -0
- package/templates/entity/new/backend/application/commands/delete.ejs.t +45 -0
- package/templates/entity/new/backend/application/commands/grouped-index.ejs.t +149 -0
- package/templates/entity/new/backend/application/commands/index.ejs.t +15 -0
- package/templates/entity/new/backend/application/commands/update.ejs.t +58 -0
- package/templates/entity/new/backend/application/queries/declarative-queries.ejs.t +36 -0
- package/templates/entity/new/backend/application/queries/get-by-id.ejs.t +42 -0
- package/templates/entity/new/backend/application/queries/grouped-index.ejs.t +81 -0
- package/templates/entity/new/backend/application/queries/index.ejs.t +14 -0
- package/templates/entity/new/backend/application/queries/list.ejs.t +36 -0
- package/templates/entity/new/backend/application/schemas/_inject-index.ejs.t +7 -0
- package/templates/entity/new/backend/application/schemas/dto.ejs.t +45 -0
- package/templates/entity/new/backend/database/_inject-index.ejs.t +7 -0
- package/templates/entity/new/backend/database/electric-migration.ejs.t +21 -0
- package/templates/entity/new/backend/database/repository.ejs.t +450 -0
- package/templates/entity/new/backend/database/schema.ejs.t +248 -0
- package/templates/entity/new/backend/domain/_inject-index.ejs.t +12 -0
- package/templates/entity/new/backend/domain/entity.ejs.t +108 -0
- package/templates/entity/new/backend/domain/grouped-index.ejs.t +163 -0
- package/templates/entity/new/backend/domain/index.ejs.t +15 -0
- package/templates/entity/new/backend/domain/repository-interface.ejs.t +71 -0
- package/templates/entity/new/backend/modules/core/_ensure-anchor-tokens.ejs.t +10 -0
- package/templates/entity/new/backend/modules/core/_inject-token.ejs.t +7 -0
- package/templates/entity/new/backend/modules/core/module.ejs.t +67 -0
- package/templates/entity/new/backend/modules/trpc/module.ejs.t +67 -0
- package/templates/entity/new/backend/presentation/controller.ejs.t +201 -0
- package/templates/entity/new/clean-lite-ps/controller.ejs.t +37 -0
- package/templates/entity/new/clean-lite-ps/dto/create.ejs.t +17 -0
- package/templates/entity/new/clean-lite-ps/dto/output.ejs.t +25 -0
- package/templates/entity/new/clean-lite-ps/dto/update.ejs.t +11 -0
- package/templates/entity/new/clean-lite-ps/entity.ejs.t +52 -0
- package/templates/entity/new/clean-lite-ps/index.ejs.t +20 -0
- package/templates/entity/new/clean-lite-ps/module.ejs.t +43 -0
- package/templates/entity/new/clean-lite-ps/prompt-extension.js +617 -0
- package/templates/entity/new/clean-lite-ps/repository.ejs.t +62 -0
- package/templates/entity/new/clean-lite-ps/service.ejs.t +34 -0
- package/templates/entity/new/clean-lite-ps/use-cases/declarative-queries.ejs.t +34 -0
- package/templates/entity/new/clean-lite-ps/use-cases/find-by-id.ejs.t +16 -0
- package/templates/entity/new/clean-lite-ps/use-cases/list.ejs.t +16 -0
- package/templates/entity/new/frontend/_inject-entities-entry.ejs.t +7 -0
- package/templates/entity/new/frontend/_inject-entities-import.ejs.t +7 -0
- package/templates/entity/new/frontend/collections/_ensure-anchor-collections.ejs.t +10 -0
- package/templates/entity/new/frontend/collections/_inject-index.ejs.t +9 -0
- package/templates/entity/new/frontend/collections/_inject-schema-import.ejs.t +9 -0
- package/templates/entity/new/frontend/collections/collection.ejs.t +61 -0
- package/templates/entity/new/frontend/collections/collections-base.ejs.t +24 -0
- package/templates/entity/new/frontend/entity/collection.ejs.t +172 -0
- package/templates/entity/new/frontend/entity/combined.ejs.t +474 -0
- package/templates/entity/new/frontend/entity/fields.ejs.t +104 -0
- package/templates/entity/new/frontend/entity/hooks.ejs.t +73 -0
- package/templates/entity/new/frontend/entity/index.ejs.t +21 -0
- package/templates/entity/new/frontend/entity/mutation-hooks.ejs.t +84 -0
- package/templates/entity/new/frontend/entity/mutations.ejs.t +38 -0
- package/templates/entity/new/frontend/entity/types.ejs.t +59 -0
- package/templates/entity/new/frontend/generated/_inject-index-export.ejs.t +7 -0
- package/templates/entity/new/frontend/generated/_inject-index-import.ejs.t +7 -0
- package/templates/entity/new/frontend/generated/_inject-index-registry.ejs.t +7 -0
- package/templates/entity/new/frontend/store/_inject-collection-import.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-collections.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-entity.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-import.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-lookups.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-resolve.ejs.t +10 -0
- package/templates/entity/new/frontend/store/hooks.ejs.t +72 -0
- package/templates/entity/new/frontend/unified-entity.ejs.t +28 -0
- package/templates/entity/new/prompt.js +1421 -0
- package/templates/relationship/new/controller.ejs.t +36 -0
- package/templates/relationship/new/dto/create.ejs.t +41 -0
- package/templates/relationship/new/dto/output.ejs.t +44 -0
- package/templates/relationship/new/dto/update.ejs.t +10 -0
- package/templates/relationship/new/entity.ejs.t +98 -0
- package/templates/relationship/new/index.ejs.t +19 -0
- package/templates/relationship/new/module.ejs.t +35 -0
- package/templates/relationship/new/prompt.js +682 -0
- package/templates/relationship/new/repository.ejs.t +54 -0
- package/templates/relationship/new/service.ejs.t +31 -0
- package/templates/relationship/new/use-cases/declarative-queries.ejs.t +34 -0
- package/templates/relationship/new/use-cases/find-by-id.ejs.t +16 -0
- 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,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
|
+
});
|