@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,248 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= generate.drizzleSchema ? outputPaths.drizzleSchema : '' %>"
|
|
3
|
+
skip_if: <%= !isCleanArchitecture %>
|
|
4
|
+
force: true
|
|
5
|
+
---
|
|
6
|
+
/**
|
|
7
|
+
* <%= className %> Drizzle Schema
|
|
8
|
+
* Generated by entity codegen - do not edit directly
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
<% if (hasRelationships) { -%>
|
|
12
|
+
import { relations } from 'drizzle-orm';
|
|
13
|
+
<% } -%>
|
|
14
|
+
<%
|
|
15
|
+
// Database dialect-specific imports
|
|
16
|
+
const isPostgres = databaseDialect === 'postgres';
|
|
17
|
+
const isSqlite = databaseDialect === 'sqlite';
|
|
18
|
+
const dbCore = isPostgres ? 'drizzle-orm/pg-core' : 'drizzle-orm/sqlite-core';
|
|
19
|
+
|
|
20
|
+
// Map Postgres imports to SQLite equivalents
|
|
21
|
+
const sqliteImportMap = {
|
|
22
|
+
'pgTable': 'sqliteTable',
|
|
23
|
+
'pgEnum': 'text', // SQLite doesn't have native enums
|
|
24
|
+
'uuid': 'text',
|
|
25
|
+
'varchar': 'text',
|
|
26
|
+
'numeric': 'real',
|
|
27
|
+
'timestamp': 'integer', // Use Unix timestamps for SQLite
|
|
28
|
+
'date': 'text', // ISO 8601 date strings
|
|
29
|
+
'jsonb': 'text', // JSON as text in SQLite
|
|
30
|
+
'boolean': 'integer', // 0/1 in SQLite
|
|
31
|
+
'integer': 'integer',
|
|
32
|
+
'text': 'text',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Get imports based on dialect
|
|
36
|
+
const dialectImports = isSqlite
|
|
37
|
+
? [...new Set(drizzleImports.map(imp => sqliteImportMap[imp] || imp))]
|
|
38
|
+
: drizzleImports;
|
|
39
|
+
|
|
40
|
+
// Determine if we need index import
|
|
41
|
+
const needsIndex = hasEntityRefFields || belongsToRelations.length > 0 || fields.some(f => f.index);
|
|
42
|
+
-%>
|
|
43
|
+
import {
|
|
44
|
+
<% dialectImports.forEach((imp) => { -%>
|
|
45
|
+
<%= imp %>,
|
|
46
|
+
<% }) -%>
|
|
47
|
+
<% if (needsIndex) { -%>
|
|
48
|
+
index,
|
|
49
|
+
<% } -%>
|
|
50
|
+
} from '<%= dbCore %>';
|
|
51
|
+
<%
|
|
52
|
+
// Collect unique non-self-referential schema imports
|
|
53
|
+
const importedSchemas = new Set();
|
|
54
|
+
[...belongsToRelations, ...hasManyRelations, ...hasOneRelations].forEach((rel) => {
|
|
55
|
+
if (rel.targetPlural !== plural) {
|
|
56
|
+
importedSchemas.add(rel.targetPlural);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
-%>
|
|
60
|
+
<% importedSchemas.forEach((targetPlural) => { -%>
|
|
61
|
+
import { <%= targetPlural %> } from './<%= targetPlural %>.schema';
|
|
62
|
+
<% }) -%>
|
|
63
|
+
<% if (hasEntityRefFields) { -%>
|
|
64
|
+
import { entityTypeEnum } from './entity-types.schema';
|
|
65
|
+
<% } -%>
|
|
66
|
+
<% if (enumFields.length > 0 && isPostgres) { -%>
|
|
67
|
+
|
|
68
|
+
// Enum definitions (Postgres only)
|
|
69
|
+
<% enumFields.forEach((field) => { -%>
|
|
70
|
+
export const <%= field.enumName %> = pgEnum('<%= field.name %>', [<%- field.choices.map(c => `'${c}'`).join(', ') %>]);
|
|
71
|
+
<% }) -%>
|
|
72
|
+
<% } -%>
|
|
73
|
+
<%
|
|
74
|
+
// Table function name based on dialect
|
|
75
|
+
const tableFunc = isPostgres ? 'pgTable' : 'sqliteTable';
|
|
76
|
+
-%>
|
|
77
|
+
|
|
78
|
+
export const <%= plural %> = <%= tableFunc %>('<%= table %>', {
|
|
79
|
+
<% if (isPostgres) { -%>
|
|
80
|
+
id: uuid('id').defaultRandom().primaryKey(),
|
|
81
|
+
<% } else { -%>
|
|
82
|
+
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
83
|
+
<% } -%>
|
|
84
|
+
<% fields.forEach((field) => { -%>
|
|
85
|
+
<% const colName = field.name.replace(/([A-Z])/g, '_$1').toLowerCase(); -%>
|
|
86
|
+
<% // Check if this field is a FK for a belongs_to relationship -%>
|
|
87
|
+
<% const belongsToRel = belongsToRelations.find(r => r.foreignKeyCamel === field.camelName); -%>
|
|
88
|
+
<% if (field.drizzleType === 'entity_type_enum') { -%>
|
|
89
|
+
<% if (isPostgres) { -%>
|
|
90
|
+
<%= field.camelName %>: entityTypeEnum('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
91
|
+
<% } else { -%>
|
|
92
|
+
<%= field.camelName %>: text('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
93
|
+
<% } -%>
|
|
94
|
+
<% } else if (field.drizzleType === 'text_array') { -%>
|
|
95
|
+
<% if (isPostgres) { -%>
|
|
96
|
+
<%= field.camelName %>: text('<%= colName %>').array()<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
97
|
+
<% } else { -%>
|
|
98
|
+
<%= field.camelName %>: text('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>, // JSON array in SQLite
|
|
99
|
+
<% } -%>
|
|
100
|
+
<% } else if (field.drizzleType === 'enum') { -%>
|
|
101
|
+
<% if (isPostgres) { -%>
|
|
102
|
+
<%= field.camelName %>: <%= field.enumName %>('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
103
|
+
<% } else { -%>
|
|
104
|
+
<%= field.camelName %>: text('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>, // Enum as text in SQLite
|
|
105
|
+
<% } -%>
|
|
106
|
+
<% } else if (field.drizzleType === 'varchar') { -%>
|
|
107
|
+
<% if (isPostgres) { -%>
|
|
108
|
+
<%= field.camelName %>: varchar('<%= colName %>'<%= field.maxLength ? `, { length: ${field.maxLength} }` : '' %>)<%= field.required && !field.nullable ? '.notNull()' : '' %><%= field.unique ? '.unique()' : '' %>,
|
|
109
|
+
<% } else { -%>
|
|
110
|
+
<%= field.camelName %>: text('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %><%= field.unique ? '.unique()' : '' %>,
|
|
111
|
+
<% } -%>
|
|
112
|
+
<% } else if (field.drizzleType === 'uuid') { -%>
|
|
113
|
+
<% if (belongsToRel) { -%>
|
|
114
|
+
<% if (isPostgres) { -%>
|
|
115
|
+
<%= field.camelName %>: uuid('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>.references(() => <%= belongsToRel.targetPlural %>.id),
|
|
116
|
+
<% } else { -%>
|
|
117
|
+
<%= field.camelName %>: text('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>.references(() => <%= belongsToRel.targetPlural %>.id),
|
|
118
|
+
<% } -%>
|
|
119
|
+
<% } else { -%>
|
|
120
|
+
<% if (isPostgres) { -%>
|
|
121
|
+
<%= field.camelName %>: uuid('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %><%= field.unique ? '.unique()' : '' %>,
|
|
122
|
+
<% } else { -%>
|
|
123
|
+
<%= field.camelName %>: text('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %><%= field.unique ? '.unique()' : '' %>,
|
|
124
|
+
<% } -%>
|
|
125
|
+
<% } -%>
|
|
126
|
+
<% } else if (field.drizzleType === 'integer') { -%>
|
|
127
|
+
<%= field.camelName %>: integer('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
128
|
+
<% } else if (field.drizzleType === 'decimal') { -%>
|
|
129
|
+
<% if (isPostgres) { -%>
|
|
130
|
+
<%= field.camelName %>: numeric('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
131
|
+
<% } else { -%>
|
|
132
|
+
<%= field.camelName %>: real('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
133
|
+
<% } -%>
|
|
134
|
+
<% } else if (field.drizzleType === 'boolean') { -%>
|
|
135
|
+
<% if (isPostgres) { -%>
|
|
136
|
+
<%= field.camelName %>: boolean('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %><%= field.default !== undefined ? `.default(${field.default})` : '' %>,
|
|
137
|
+
<% } else { -%>
|
|
138
|
+
<%= field.camelName %>: integer('<%= colName %>', { mode: 'boolean' })<%= field.required && !field.nullable ? '.notNull()' : '' %><%= field.default !== undefined ? `.default(${field.default ? 1 : 0})` : '' %>,
|
|
139
|
+
<% } -%>
|
|
140
|
+
<% } else if (field.drizzleType === 'date') { -%>
|
|
141
|
+
<% if (isPostgres) { -%>
|
|
142
|
+
<%= field.camelName %>: date('<%= colName %>', { mode: 'date' })<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
143
|
+
<% } else { -%>
|
|
144
|
+
<%= field.camelName %>: text('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>, // ISO 8601 date string
|
|
145
|
+
<% } -%>
|
|
146
|
+
<% } else if (field.drizzleType === 'timestamp') { -%>
|
|
147
|
+
<% if (isPostgres) { -%>
|
|
148
|
+
<%= field.camelName %>: timestamp('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
149
|
+
<% } else { -%>
|
|
150
|
+
<%= field.camelName %>: integer('<%= colName %>', { mode: 'timestamp' })<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
151
|
+
<% } -%>
|
|
152
|
+
<% } else if (field.drizzleType === 'jsonb') { -%>
|
|
153
|
+
<% if (isPostgres) { -%>
|
|
154
|
+
<%= field.camelName %>: jsonb('<%= colName %>')<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
155
|
+
<% } else { -%>
|
|
156
|
+
<%= field.camelName %>: text('<%= colName %>', { mode: 'json' })<%= field.required && !field.nullable ? '.notNull()' : '' %>,
|
|
157
|
+
<% } -%>
|
|
158
|
+
<% } -%>
|
|
159
|
+
<% }) -%>
|
|
160
|
+
<% /* ================================================================== */ -%>
|
|
161
|
+
<% /* Behavior fields - generated based on behaviors array */ -%>
|
|
162
|
+
<% /* ================================================================== */ -%>
|
|
163
|
+
<% if (hasTimestamps) { -%>
|
|
164
|
+
// timestamps behavior
|
|
165
|
+
<% if (isPostgres) { -%>
|
|
166
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
167
|
+
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
168
|
+
<% } else { -%>
|
|
169
|
+
createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => new Date()).notNull(),
|
|
170
|
+
updatedAt: integer('updated_at', { mode: 'timestamp' }).$defaultFn(() => new Date()).notNull(),
|
|
171
|
+
<% } -%>
|
|
172
|
+
<% } -%>
|
|
173
|
+
<% if (hasSoftDelete) { -%>
|
|
174
|
+
// soft_delete behavior
|
|
175
|
+
<% if (isPostgres) { -%>
|
|
176
|
+
deletedAt: timestamp('deleted_at'),
|
|
177
|
+
<% } else { -%>
|
|
178
|
+
deletedAt: integer('deleted_at', { mode: 'timestamp' }),
|
|
179
|
+
<% } -%>
|
|
180
|
+
<% } -%>
|
|
181
|
+
<% if (hasUserTracking) { -%>
|
|
182
|
+
// user_tracking behavior
|
|
183
|
+
<% if (isPostgres) { -%>
|
|
184
|
+
createdBy: uuid('created_by'),
|
|
185
|
+
updatedBy: uuid('updated_by'),
|
|
186
|
+
<% } else { -%>
|
|
187
|
+
createdBy: text('created_by'),
|
|
188
|
+
updatedBy: text('updated_by'),
|
|
189
|
+
<% } -%>
|
|
190
|
+
<% } -%>
|
|
191
|
+
<% if (hasTemporalValidity) { -%>
|
|
192
|
+
// temporal_validity behavior
|
|
193
|
+
<% if (isPostgres) { -%>
|
|
194
|
+
validFrom: timestamp('valid_from'),
|
|
195
|
+
validTo: timestamp('valid_to'),
|
|
196
|
+
isActive: boolean('is_active').default(true).notNull(),
|
|
197
|
+
<% } else { -%>
|
|
198
|
+
validFrom: integer('valid_from', { mode: 'timestamp' }),
|
|
199
|
+
validTo: integer('valid_to', { mode: 'timestamp' }),
|
|
200
|
+
isActive: integer('is_active', { mode: 'boolean' }).default(1).notNull(),
|
|
201
|
+
<% } -%>
|
|
202
|
+
<% } -%>
|
|
203
|
+
}<%
|
|
204
|
+
// Determine if we need a table config function for indexes
|
|
205
|
+
const fkIndexes = belongsToRelations.map(rel => ({
|
|
206
|
+
name: rel.foreignKeyCamel,
|
|
207
|
+
colName: rel.foreignKey.replace(/([A-Z])/g, '_$1').toLowerCase()
|
|
208
|
+
}));
|
|
209
|
+
const fieldIndexes = fields.filter(f => f.index).map(f => ({
|
|
210
|
+
name: f.camelName,
|
|
211
|
+
colName: f.name.replace(/([A-Z])/g, '_$1').toLowerCase()
|
|
212
|
+
}));
|
|
213
|
+
const allIndexes = [...fkIndexes, ...fieldIndexes];
|
|
214
|
+
const hasTableConfig = hasEntityRefFields || allIndexes.length > 0;
|
|
215
|
+
-%>
|
|
216
|
+
<% if (hasTableConfig) { -%>, (table) => ({
|
|
217
|
+
<% entityRefFields.forEach((ref) => { -%>
|
|
218
|
+
<%= ref.camelName %>Idx: index('idx_<%= table %>_<%= ref.name %>').on(table.<%= ref.camelName %>EntityType, table.<%= ref.camelName %>EntityId),
|
|
219
|
+
<% }) -%>
|
|
220
|
+
<% allIndexes.forEach((idx) => { -%>
|
|
221
|
+
<%= idx.name %>Idx: index('idx_<%= table %>_<%= idx.colName %>').on(table.<%= idx.name %>),
|
|
222
|
+
<% }) -%>
|
|
223
|
+
})<% } -%>);
|
|
224
|
+
<% if (hasRelationships) { -%>
|
|
225
|
+
<%
|
|
226
|
+
const usesOne = belongsToRelations.length > 0 || hasOneRelations.length > 0;
|
|
227
|
+
const usesMany = hasManyRelations.length > 0;
|
|
228
|
+
const destructured = [usesOne ? 'one' : '', usesMany ? 'many' : ''].filter(Boolean).join(', ');
|
|
229
|
+
-%>
|
|
230
|
+
|
|
231
|
+
export const <%= plural %>Relations = relations(<%= plural %>, ({ <%= destructured %> }) => ({
|
|
232
|
+
<% belongsToRelations.forEach((rel) => { -%>
|
|
233
|
+
<%= rel.name %>: one(<%= rel.targetPlural %>, {
|
|
234
|
+
fields: [<%= plural %>.<%= rel.foreignKeyCamel %>],
|
|
235
|
+
references: [<%= rel.targetPlural %>.id],
|
|
236
|
+
}),
|
|
237
|
+
<% }) -%>
|
|
238
|
+
<% hasManyRelations.forEach((rel) => { -%>
|
|
239
|
+
<%= rel.name %>: many(<%= rel.targetPlural %>),
|
|
240
|
+
<% }) -%>
|
|
241
|
+
<% hasOneRelations.forEach((rel) => { -%>
|
|
242
|
+
<%= rel.name %>: one(<%= rel.targetPlural %>),
|
|
243
|
+
<% }) -%>
|
|
244
|
+
}));
|
|
245
|
+
<% } -%>
|
|
246
|
+
|
|
247
|
+
export type <%= className %>Record = typeof <%= plural %>.$inferSelect;
|
|
248
|
+
export type New<%= className %>Record = typeof <%= plural %>.$inferInsert;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= isCleanArchitecture ? `${basePaths.backendSrc}/${backendLayers.domain}/index.ts` : '' %>"
|
|
3
|
+
inject: true
|
|
4
|
+
append: true
|
|
5
|
+
skip_if: <%= name %>
|
|
6
|
+
---
|
|
7
|
+
<% if (isNested) { -%>
|
|
8
|
+
export * from './<%= name %>';
|
|
9
|
+
<% } else { -%>
|
|
10
|
+
export * from './<%= name %>.entity';
|
|
11
|
+
export * from './<%= name %>.repository.interface';
|
|
12
|
+
<% } -%>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: <%= outputPaths.entity %>
|
|
3
|
+
skip_if: <%= !isCleanArchitecture %>
|
|
4
|
+
force: true
|
|
5
|
+
---
|
|
6
|
+
<% if (outputPaths.entity) { -%>
|
|
7
|
+
/**
|
|
8
|
+
* <%= className %> Domain Entity
|
|
9
|
+
* Generated by entity codegen - do not edit directly
|
|
10
|
+
*
|
|
11
|
+
* NOTE: Related entity imports assume a nested folder structure where each entity
|
|
12
|
+
* lives in its own folder (e.g., domain/{entity}/{entity}.entity.ts). This follows
|
|
13
|
+
* CLEAN architecture conventions where each aggregate root has its own bounded context.
|
|
14
|
+
* All entities should follow this structure for consistent imports.
|
|
15
|
+
*/
|
|
16
|
+
<% if (hasEntityRefFields) { -%>
|
|
17
|
+
import type { EntityType } from '<%= locations.dbSchemaServer.import %>';
|
|
18
|
+
<% } -%>
|
|
19
|
+
<%
|
|
20
|
+
// Collect unique non-self-referential imports
|
|
21
|
+
const importedEntities = new Set();
|
|
22
|
+
[...belongsToRelations, ...hasManyRelations, ...hasOneRelations].forEach((rel) => {
|
|
23
|
+
if (rel.target !== name) {
|
|
24
|
+
importedEntities.add(rel.target);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
-%>
|
|
28
|
+
<% if (importedEntities.size > 0) { -%>
|
|
29
|
+
|
|
30
|
+
<% importedEntities.forEach((target) => {
|
|
31
|
+
const targetClass = target.charAt(0).toUpperCase() + target.slice(1).replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
32
|
+
-%>
|
|
33
|
+
import type { <%= targetClass %> } from '../<%= target %>/<%= target %>.entity';
|
|
34
|
+
<% }) -%>
|
|
35
|
+
<% } -%>
|
|
36
|
+
|
|
37
|
+
export class <%= className %> {
|
|
38
|
+
constructor(
|
|
39
|
+
public readonly id: string,
|
|
40
|
+
<% fields.forEach((field) => { -%>
|
|
41
|
+
public readonly <%= field.camelName %>: <%- field.tsType %><%= field.nullable ? ' | null' : '' %>,
|
|
42
|
+
<% }) -%>
|
|
43
|
+
<% if (hasTimestamps) { -%>
|
|
44
|
+
public readonly createdAt: Date,
|
|
45
|
+
public readonly updatedAt: Date,
|
|
46
|
+
<% } -%>
|
|
47
|
+
<% if (hasSoftDelete) { -%>
|
|
48
|
+
public readonly deletedAt: Date | null,
|
|
49
|
+
<% } -%>
|
|
50
|
+
<% if (hasTemporalValidity) { -%>
|
|
51
|
+
public readonly validFrom: Date | null,
|
|
52
|
+
public readonly validTo: Date | null,
|
|
53
|
+
public readonly isActive: boolean,
|
|
54
|
+
<% } -%>
|
|
55
|
+
<% if (hasRelationships) { -%>
|
|
56
|
+
// Loaded relations (optional, populated when eager-loaded)
|
|
57
|
+
<% belongsToRelations.forEach((rel) => { -%>
|
|
58
|
+
public readonly <%= rel.name %>?: <%= rel.targetClass %>,
|
|
59
|
+
<% }) -%>
|
|
60
|
+
<% hasManyRelations.forEach((rel) => { -%>
|
|
61
|
+
public readonly <%= rel.name %>?: <%= rel.targetClass %>[],
|
|
62
|
+
<% }) -%>
|
|
63
|
+
<% hasOneRelations.forEach((rel) => { -%>
|
|
64
|
+
public readonly <%= rel.name %>?: <%= rel.targetClass %>,
|
|
65
|
+
<% }) -%>
|
|
66
|
+
<% } -%>
|
|
67
|
+
) {}
|
|
68
|
+
|
|
69
|
+
static fromRecord(
|
|
70
|
+
// biome-ignore lint/suspicious/noExplicitAny: Drizzle records have dynamic shape
|
|
71
|
+
record: Record<string, any>,
|
|
72
|
+
<% if (hasRelationships) { -%>
|
|
73
|
+
// biome-ignore lint/suspicious/noExplicitAny: Returns different entity types
|
|
74
|
+
mapRelation?: (name: string, data: unknown) => any,
|
|
75
|
+
<% } -%>
|
|
76
|
+
): <%= className %> {
|
|
77
|
+
return new <%= className %>(
|
|
78
|
+
record.id,
|
|
79
|
+
<% fields.forEach((field) => { -%>
|
|
80
|
+
record.<%= field.camelName %>,
|
|
81
|
+
<% }) -%>
|
|
82
|
+
<% if (hasTimestamps) { -%>
|
|
83
|
+
record.createdAt,
|
|
84
|
+
record.updatedAt,
|
|
85
|
+
<% } -%>
|
|
86
|
+
<% if (hasSoftDelete) { -%>
|
|
87
|
+
record.deletedAt,
|
|
88
|
+
<% } -%>
|
|
89
|
+
<% if (hasTemporalValidity) { -%>
|
|
90
|
+
record.validFrom,
|
|
91
|
+
record.validTo,
|
|
92
|
+
record.isActive,
|
|
93
|
+
<% } -%>
|
|
94
|
+
<% if (hasRelationships) { -%>
|
|
95
|
+
<% belongsToRelations.forEach((rel) => { -%>
|
|
96
|
+
record.<%= rel.name %> ? mapRelation?.('<%= rel.name %>', record.<%= rel.name %>) : undefined,
|
|
97
|
+
<% }) -%>
|
|
98
|
+
<% hasManyRelations.forEach((rel) => { -%>
|
|
99
|
+
record.<%= rel.name %> ? mapRelation?.('<%= rel.name %>', record.<%= rel.name %>) : undefined,
|
|
100
|
+
<% }) -%>
|
|
101
|
+
<% hasOneRelations.forEach((rel) => { -%>
|
|
102
|
+
record.<%= rel.name %> ? mapRelation?.('<%= rel.name %>', record.<%= rel.name %>) : undefined,
|
|
103
|
+
<% }) -%>
|
|
104
|
+
<% } -%>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
<% } -%>
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: <%= outputPaths.domainGroupedIndex %>
|
|
3
|
+
skip_if: <%= !isCleanArchitecture %>
|
|
4
|
+
force: true
|
|
5
|
+
---
|
|
6
|
+
<% if (outputPaths.domainGroupedIndex) { -%>
|
|
7
|
+
/**
|
|
8
|
+
* <%= className %> Domain Module
|
|
9
|
+
* Generated by entity codegen - do not edit directly
|
|
10
|
+
*
|
|
11
|
+
* This file contains the domain entity and repository interface
|
|
12
|
+
* using grouped file layout (file_grouping: "grouped")
|
|
13
|
+
*/
|
|
14
|
+
<% if (hasEntityRefFields) { -%>
|
|
15
|
+
import type { EntityType } from '<%= locations.dbSchemaServer.import %>';
|
|
16
|
+
<% } -%>
|
|
17
|
+
<%
|
|
18
|
+
// Collect unique non-self-referential imports
|
|
19
|
+
const importedEntities = new Set();
|
|
20
|
+
[...belongsToRelations, ...hasManyRelations, ...hasOneRelations].forEach((rel) => {
|
|
21
|
+
if (rel.target !== name) {
|
|
22
|
+
importedEntities.add(rel.target);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
-%>
|
|
26
|
+
<% if (importedEntities.size > 0) { -%>
|
|
27
|
+
|
|
28
|
+
<% importedEntities.forEach((target) => {
|
|
29
|
+
const targetClass = target.charAt(0).toUpperCase() + target.slice(1).replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
30
|
+
-%>
|
|
31
|
+
import type { <%= targetClass %> } from '../<%= target %>';
|
|
32
|
+
<% }) -%>
|
|
33
|
+
<% } -%>
|
|
34
|
+
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Entity
|
|
37
|
+
// ============================================================================
|
|
38
|
+
|
|
39
|
+
export class <%= className %> {
|
|
40
|
+
constructor(
|
|
41
|
+
public readonly id: string,
|
|
42
|
+
<% fields.forEach((field) => { -%>
|
|
43
|
+
public readonly <%= field.camelName %>: <%- field.tsType %><%= field.nullable ? ' | null' : '' %>,
|
|
44
|
+
<% }) -%>
|
|
45
|
+
<% if (hasTimestamps) { -%>
|
|
46
|
+
public readonly createdAt: Date,
|
|
47
|
+
public readonly updatedAt: Date,
|
|
48
|
+
<% } -%>
|
|
49
|
+
<% if (hasSoftDelete) { -%>
|
|
50
|
+
public readonly deletedAt: Date | null,
|
|
51
|
+
<% } -%>
|
|
52
|
+
<% if (hasTemporalValidity) { -%>
|
|
53
|
+
public readonly validFrom: Date | null,
|
|
54
|
+
public readonly validTo: Date | null,
|
|
55
|
+
public readonly isActive: boolean,
|
|
56
|
+
<% } -%>
|
|
57
|
+
<% if (hasRelationships) { -%>
|
|
58
|
+
// Loaded relations (optional, populated when eager-loaded)
|
|
59
|
+
<% belongsToRelations.forEach((rel) => { -%>
|
|
60
|
+
public readonly <%= rel.name %>?: <%= rel.targetClass %>,
|
|
61
|
+
<% }) -%>
|
|
62
|
+
<% hasManyRelations.forEach((rel) => { -%>
|
|
63
|
+
public readonly <%= rel.name %>?: <%= rel.targetClass %>[],
|
|
64
|
+
<% }) -%>
|
|
65
|
+
<% hasOneRelations.forEach((rel) => { -%>
|
|
66
|
+
public readonly <%= rel.name %>?: <%= rel.targetClass %>,
|
|
67
|
+
<% }) -%>
|
|
68
|
+
<% } -%>
|
|
69
|
+
) {}
|
|
70
|
+
|
|
71
|
+
static fromRecord(
|
|
72
|
+
// biome-ignore lint/suspicious/noExplicitAny: Drizzle records have dynamic shape
|
|
73
|
+
record: Record<string, any>,
|
|
74
|
+
<% if (hasRelationships) { -%>
|
|
75
|
+
// biome-ignore lint/suspicious/noExplicitAny: Returns different entity types
|
|
76
|
+
mapRelation?: (name: string, data: unknown) => any,
|
|
77
|
+
<% } -%>
|
|
78
|
+
): <%= className %> {
|
|
79
|
+
return new <%= className %>(
|
|
80
|
+
record.id,
|
|
81
|
+
<% fields.forEach((field) => { -%>
|
|
82
|
+
record.<%= field.camelName %>,
|
|
83
|
+
<% }) -%>
|
|
84
|
+
<% if (hasTimestamps) { -%>
|
|
85
|
+
record.createdAt,
|
|
86
|
+
record.updatedAt,
|
|
87
|
+
<% } -%>
|
|
88
|
+
<% if (hasSoftDelete) { -%>
|
|
89
|
+
record.deletedAt,
|
|
90
|
+
<% } -%>
|
|
91
|
+
<% if (hasTemporalValidity) { -%>
|
|
92
|
+
record.validFrom,
|
|
93
|
+
record.validTo,
|
|
94
|
+
record.isActive,
|
|
95
|
+
<% } -%>
|
|
96
|
+
<% if (hasRelationships) { -%>
|
|
97
|
+
<% belongsToRelations.forEach((rel) => { -%>
|
|
98
|
+
record.<%= rel.name %> ? mapRelation?.('<%= rel.name %>', record.<%= rel.name %>) : undefined,
|
|
99
|
+
<% }) -%>
|
|
100
|
+
<% hasManyRelations.forEach((rel) => { -%>
|
|
101
|
+
record.<%= rel.name %> ? mapRelation?.('<%= rel.name %>', record.<%= rel.name %>) : undefined,
|
|
102
|
+
<% }) -%>
|
|
103
|
+
<% hasOneRelations.forEach((rel) => { -%>
|
|
104
|
+
record.<%= rel.name %> ? mapRelation?.('<%= rel.name %>', record.<%= rel.name %>) : undefined,
|
|
105
|
+
<% }) -%>
|
|
106
|
+
<% } -%>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ============================================================================
|
|
112
|
+
// Repository Interface
|
|
113
|
+
// ============================================================================
|
|
114
|
+
<% if (hasRelationships) { -%>
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Type-safe eager loading options.
|
|
118
|
+
* Pass to repository methods to include related entities.
|
|
119
|
+
*/
|
|
120
|
+
export type <%= className %>With = {
|
|
121
|
+
<% relationships.forEach((rel) => { -%>
|
|
122
|
+
<%= rel.name %>?: boolean;
|
|
123
|
+
<% }) -%>
|
|
124
|
+
};
|
|
125
|
+
<% } -%>
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Domain-level input types for repository operations.
|
|
129
|
+
*/
|
|
130
|
+
export type Create<%= className %>Input = {
|
|
131
|
+
<% fields.forEach((field) => { -%>
|
|
132
|
+
<% if (field.required) { -%>
|
|
133
|
+
<%= field.camelName %>: <%- field.tsType %>;
|
|
134
|
+
<% } else if (field.nullable) { -%>
|
|
135
|
+
<%= field.camelName %>?: <%- field.tsType %> | null;
|
|
136
|
+
<% } else { -%>
|
|
137
|
+
<%= field.camelName %>?: <%- field.tsType %>;
|
|
138
|
+
<% } -%>
|
|
139
|
+
<% }) -%>
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export type Update<%= className %>Input = Partial<Create<%= className %>Input>;
|
|
143
|
+
|
|
144
|
+
export interface I<%= className %>Repository {
|
|
145
|
+
create(input: Create<%= className %>Input): Promise<<%= className %>>;
|
|
146
|
+
findById(id: string<%= hasRelationships ? `, include?: ${className}With` : '' %>): Promise<<%= className %> | null>;
|
|
147
|
+
findAll(<%= hasRelationships ? `include?: ${className}With` : '' %>): Promise<<%= className %>[]>;
|
|
148
|
+
update(id: string, input: Update<%= className %>Input): Promise<<%= className %> | null>;
|
|
149
|
+
delete(id: string): Promise<<%= className %> | null>;
|
|
150
|
+
<% if (hasSoftDelete) { -%>
|
|
151
|
+
// Soft delete recovery methods
|
|
152
|
+
restore(id: string): Promise<<%= className %> | null>;
|
|
153
|
+
findWithDeleted(): Promise<<%= className %>[]>;
|
|
154
|
+
findOnlyDeleted(): Promise<<%= className %>[]>;
|
|
155
|
+
<% } -%>
|
|
156
|
+
<% belongsToRelations.forEach((rel) => { -%>
|
|
157
|
+
findBy<%= rel.foreignKeyPascal %>(id: string<%= hasRelationships ? `, include?: ${className}With` : '' %>): Promise<<%= className %>[]>;
|
|
158
|
+
<% }) -%>
|
|
159
|
+
<% entityRefFields.forEach((ref) => { -%>
|
|
160
|
+
findBy<%= ref.pascalName %>(entityType: EntityType, entityId: string<%= hasRelationships ? `, include?: ${className}With` : '' %>): Promise<<%= className %>[]>;
|
|
161
|
+
<% }) -%>
|
|
162
|
+
}
|
|
163
|
+
<% } -%>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: <%= basePaths.backendSrc %>/<%= paths.domain %>/index.ts
|
|
3
|
+
skip_if: <%= !isCleanArchitecture || (!isNested || isGrouped) %>
|
|
4
|
+
force: true
|
|
5
|
+
---
|
|
6
|
+
/**
|
|
7
|
+
* <%= className %> Domain Barrel Export
|
|
8
|
+
* Generated by entity codegen - do not edit directly
|
|
9
|
+
*
|
|
10
|
+
* This barrel file exports the entity and repository interface
|
|
11
|
+
* when using separate file layout (file_grouping: "separate")
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export * from './<%= name %>.entity';
|
|
15
|
+
export * from './<%= name %>.repository.interface';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: <%= outputPaths.repositoryInterface %>
|
|
3
|
+
skip_if: <%= !isCleanArchitecture %>
|
|
4
|
+
force: true
|
|
5
|
+
---
|
|
6
|
+
<% if (outputPaths.repositoryInterface) { -%>
|
|
7
|
+
/**
|
|
8
|
+
* <%= className %> Repository Interface
|
|
9
|
+
* Generated by entity codegen - do not edit directly
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { <%= className %> } from './<%= name %>.entity';
|
|
13
|
+
<% if (hasEntityRefFields) { -%>
|
|
14
|
+
import type { EntityType } from '<%= locations.dbSchemaServer.import %>';
|
|
15
|
+
<% } -%>
|
|
16
|
+
<% if (hasRelationships) { -%>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Type-safe eager loading options.
|
|
20
|
+
* Pass to repository methods to include related entities.
|
|
21
|
+
*/
|
|
22
|
+
export type <%= className %>With = {
|
|
23
|
+
<% relationships.forEach((rel) => { -%>
|
|
24
|
+
<%= rel.name %>?: boolean;
|
|
25
|
+
<% }) -%>
|
|
26
|
+
};
|
|
27
|
+
<% } -%>
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Domain-level input types for repository operations.
|
|
31
|
+
*/
|
|
32
|
+
export type Create<%= className %>Input = {
|
|
33
|
+
<% fields.forEach((field) => { -%>
|
|
34
|
+
<% if (field.required) { -%>
|
|
35
|
+
<%= field.camelName %>: <%- field.tsType %>;
|
|
36
|
+
<% } else if (field.nullable) { -%>
|
|
37
|
+
<%= field.camelName %>?: <%- field.tsType %> | null;
|
|
38
|
+
<% } else { -%>
|
|
39
|
+
<%= field.camelName %>?: <%- field.tsType %>;
|
|
40
|
+
<% } -%>
|
|
41
|
+
<% }) -%>
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type Update<%= className %>Input = Partial<Create<%= className %>Input>;
|
|
45
|
+
|
|
46
|
+
export interface I<%= className %>Repository {
|
|
47
|
+
create(input: Create<%= className %>Input): Promise<<%= className %>>;
|
|
48
|
+
findById(id: string<%= hasRelationships ? `, include?: ${className}With` : '' %>): Promise<<%= className %> | null>;
|
|
49
|
+
findAll(<%= hasRelationships ? `include?: ${className}With` : '' %>): Promise<<%= className %>[]>;
|
|
50
|
+
update(id: string, input: Update<%= className %>Input): Promise<<%= className %> | null>;
|
|
51
|
+
delete(id: string): Promise<<%= className %> | null>;
|
|
52
|
+
<% if (hasSoftDelete) { -%>
|
|
53
|
+
// Soft delete recovery methods
|
|
54
|
+
restore(id: string): Promise<<%= className %> | null>;
|
|
55
|
+
findWithDeleted(): Promise<<%= className %>[]>;
|
|
56
|
+
findOnlyDeleted(): Promise<<%= className %>[]>;
|
|
57
|
+
<% } -%>
|
|
58
|
+
<% belongsToRelations.forEach((rel) => { -%>
|
|
59
|
+
findBy<%= rel.foreignKeyPascal %>(id: string<%= hasRelationships ? `, include?: ${className}With` : '' %>): Promise<<%= className %>[]>;
|
|
60
|
+
<% }) -%>
|
|
61
|
+
<% entityRefFields.forEach((ref) => { -%>
|
|
62
|
+
findBy<%= ref.pascalName %>(entityType: EntityType, entityId: string<%= hasRelationships ? `, include?: ${className}With` : '' %>): Promise<<%= className %>[]>;
|
|
63
|
+
<% }) -%>
|
|
64
|
+
<% if (hasDeclarativeQueries) { -%>
|
|
65
|
+
// Declarative queries (from queries: block in entity YAML)
|
|
66
|
+
<% processedQueries.forEach((q) => { -%>
|
|
67
|
+
<%= q.methodName %>(<%- q.params.map(p => `${p.camelName}: ${p.tsType}`).join(', ') %>): Promise<<%- q.returnType %>>;
|
|
68
|
+
<% }) -%>
|
|
69
|
+
<% } -%>
|
|
70
|
+
}
|
|
71
|
+
<% } -%>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= isCleanArchitecture ? (exposeRepository ? `${locations.backendConstants.path}/tokens.ts` : '') : '' %>"
|
|
3
|
+
inject: true
|
|
4
|
+
append: true
|
|
5
|
+
skip_if: "// Generated entity repository tokens"
|
|
6
|
+
---
|
|
7
|
+
<% if (exposeRepository) { -%>
|
|
8
|
+
|
|
9
|
+
// Generated entity repository tokens
|
|
10
|
+
<% } -%>
|