@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Noun-verb CLI** — Clipanion-based CLI replacing the legacy single-file handler. Commands: `entity`, `subsystem`, `project`, `dev`. Each noun has a summary pane with dynamic hints. (ADR-015)
|
|
9
|
+
- **UI toolkit** — chalk theme tokens, icons with ASCII fallback, Ora spinners, pane/hints rendering, `--json` mode across all commands. (ADR-016)
|
|
10
|
+
- **Barrel files** — `src/generated/modules.ts` and `src/generated/schema.ts` replace app.module.ts injection. Codegen never touches user-authored files. (ADR-017)
|
|
11
|
+
- **`codegen init`** — scaffolds a consumer project: codegen.config.yaml, tsconfig path aliases, DatabaseModule, runtime shims, empty barrels, example entity YAML.
|
|
12
|
+
- **`codegen dev`** — manages Docker services (Postgres + Redis), starts/stops the NestJS app, shows health dashboard with endpoint probing.
|
|
13
|
+
- **Redis event bus** — `EventsModule.forRoot({ backend: 'redis' })` using ioredis Pub/Sub. Optional peer dependency.
|
|
14
|
+
- **Declarative query methods on repository** — clean-lite-ps repository template now generates `findByX` methods from the `queries:` block.
|
|
15
|
+
- **Smoke test harness** — `just test-smoke` scaffolds a fresh project, generates entities, runs `tsc --noEmit`. Catches template and import regressions.
|
|
16
|
+
- **Consumer setup docs** — `docs/CONSUMER-SETUP.md` covering the full wire-up contract: tsconfig aliases, DatabaseModule, runtime shims, barrels.
|
|
17
|
+
- **Browser-pilot agent** — Playwright + Chrome DevTools + Lighthouse MCP for endpoint verification and visual QA.
|
|
18
|
+
- **Team agents** — architect, builder, coordinator, validator adapted for codegen-patterns workflows.
|
|
19
|
+
- **Dev companion commands** — `/dev-check`, `/dev-test`, `/dev-debug` for interactive development with teammate/subagent fallback.
|
|
20
|
+
- **Claude Code skill** — `.claude/skills/codegen/SKILL.md` teaches Claude the full CLI reference. Install with `just install-skill <target>`.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- **Package renamed** from `@anthropic/codegen` to `@pattern-stack/codegen`.
|
|
24
|
+
- **Repo reorganized** — source under `src/`, shipped runtime under `runtime/`, tests under `src/__tests__/`. Root cut from ~17 directories to 5.
|
|
25
|
+
- **`output/` renamed to `src/formatters/`** for clarity.
|
|
26
|
+
- **`shared/` renamed to `runtime/`** — makes the generator-vs-emitted boundary visible.
|
|
27
|
+
- **`generate.cleanLitePs`** replaced by `generate.architecture: 'clean' | 'clean-lite-ps'` enum. No deprecation shim (no existing users).
|
|
28
|
+
- **`generate.frontend`** added (default `false`). Scanner flips true when `apps/frontend/` detected.
|
|
29
|
+
- **Use case naming** — declarative queries now emit entity-prefixed names (`FindAccountByDomainUseCase`, not `FindByDomainUseCase`). Prevents cross-entity collisions.
|
|
30
|
+
- **WithAnalytics mixin** — preserves abstract base class type and method signatures through the mixin chain.
|
|
31
|
+
- **`baseQuery()`** uses Drizzle `$dynamic()` for consistent return type. Fixes `.where()` chaining in all family repositories.
|
|
32
|
+
- **Subsystem install default path** — `shared/subsystems/` (was `src/shared/subsystems/`).
|
|
33
|
+
- **Drizzle backend filter** — `subsystem install --backend drizzle` now keeps memory backend too (needed for tests).
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- Clean-lite-ps and clean-architecture templates no longer both emit when one is selected.
|
|
37
|
+
- Frontend templates no longer emit when `generate.frontend` is false.
|
|
38
|
+
- `app.module.ts` injection removed entirely (replaced by barrels).
|
|
39
|
+
- Templates dir resolves correctly when CLI invoked from outside the repo.
|
|
40
|
+
- WithAnalytics template import changed from `base-analytics-service` to `with-analytics` (matches runtime filename).
|
|
41
|
+
- EJS HTML-escape in declarative query templates — enum union types (`'active' | 'inactive'`) no longer rendered as `'active'`.
|
|
42
|
+
- Validator includes `belongs_to` foreign key fields in available-fields set for query validation.
|
|
43
|
+
- `MetadataEntityRepository.upsertMany` signature matches base class (conflictTarget now optional).
|
|
44
|
+
- `Column` import from drizzle-orm/pg-core changed to `PgColumn` (matches 0.45 exports).
|
|
45
|
+
- `prompt.js` config imports fixed after `src/` reorg.
|
|
46
|
+
|
|
47
|
+
### Removed
|
|
48
|
+
- Legacy `src/cli.ts` (25K single-file CLI) — replaced by `src/cli/` noun-verb architecture.
|
|
49
|
+
- 11 Hygen inject templates that mutated `app.module.ts` and `schema.ts`.
|
|
50
|
+
- Stale docs: `CODEGEN-EVOLUTION-PLAN.md`, `SNAKE_CAMEL_SYNC.md`, `context-engine.md`, `v2-initiative-overview.md`, `contact-module-sketch.md`.
|
|
51
|
+
- Empty `tools/` directory.
|
|
52
|
+
|
|
53
|
+
## [0.2.0] - 2026-04-12
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
- Infrastructure subsystems: events, jobs, cache, storage (ADR-008). Protocol → Backend → Factory pattern.
|
|
57
|
+
- CRM family renamed to Synced (domain-agnostic).
|
|
58
|
+
- Getting Started guide.
|
|
59
|
+
- Declarative query codegen from `queries:` YAML block.
|
|
60
|
+
- Clean-Lite-PS template pipeline.
|
|
61
|
+
- Entity family base classes (synced, activity, metadata, knowledge).
|
|
62
|
+
- BaseRepository and BaseService with behavior injection.
|
|
63
|
+
- Project scanner for convention detection.
|
|
64
|
+
|
|
65
|
+
## [0.1.0] - 2026-04-12
|
|
66
|
+
|
|
67
|
+
Initial release. YAML schema, parser, analyzer, Hygen template pipeline, baseline test infrastructure.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# codegen-patterns
|
|
2
|
+
|
|
3
|
+
Define entities in YAML. Generate a full NestJS + Drizzle backend — repositories, services, controllers, DTOs, use cases, module wiring — in one command.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
codegen entity new entities/contact.yaml
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Built for teams that want consistent architecture without hand-writing the same CRUD scaffolding for every entity. Works with two backend layouts (full Clean Architecture or Clean-Lite-PS) and generates infrastructure subsystems (events, jobs, cache, storage) following Protocol → Backend → Factory patterns.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bun install # install deps
|
|
15
|
+
mise install # pin bun + node versions (optional, recommended)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Define an Entity
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
# entities/contact.yaml
|
|
22
|
+
entity:
|
|
23
|
+
name: contact
|
|
24
|
+
plural: contacts
|
|
25
|
+
table: contacts
|
|
26
|
+
family: synced # synced | activity | metadata | knowledge
|
|
27
|
+
|
|
28
|
+
fields:
|
|
29
|
+
email:
|
|
30
|
+
type: string
|
|
31
|
+
required: true
|
|
32
|
+
max_length: 255
|
|
33
|
+
index: true
|
|
34
|
+
first_name:
|
|
35
|
+
type: string
|
|
36
|
+
required: true
|
|
37
|
+
status:
|
|
38
|
+
type: enum
|
|
39
|
+
choices: [active, inactive]
|
|
40
|
+
|
|
41
|
+
behaviors:
|
|
42
|
+
- timestamps # createdAt, updatedAt
|
|
43
|
+
- soft_delete # deletedAt + automatic query filtering
|
|
44
|
+
|
|
45
|
+
relationships:
|
|
46
|
+
account:
|
|
47
|
+
type: belongs_to
|
|
48
|
+
target: account
|
|
49
|
+
foreign_key: account_id
|
|
50
|
+
|
|
51
|
+
queries:
|
|
52
|
+
- by: [email]
|
|
53
|
+
unique: true
|
|
54
|
+
- by: [account_id]
|
|
55
|
+
order: created_at desc
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Generate
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
codegen entity new entities/contact.yaml # one entity
|
|
62
|
+
codegen entity new --all # all entities
|
|
63
|
+
codegen entity validate # check YAML before generating
|
|
64
|
+
codegen entity list # see what's defined
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Every run regenerates barrel files (`src/generated/modules.ts` and `src/generated/schema.ts`) so your `app.module.ts` never needs editing after the initial one-line wire-up.
|
|
68
|
+
|
|
69
|
+
## CLI
|
|
70
|
+
|
|
71
|
+
The CLI uses a noun-verb pattern. Running any noun alone shows its current state and suggests next steps:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
codegen # project overview
|
|
75
|
+
codegen entity # entity summary + hints
|
|
76
|
+
codegen subsystem # installed vs available
|
|
77
|
+
codegen project # config + framework detection
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Entity Commands
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
codegen entity new <yaml> # generate from YAML
|
|
84
|
+
codegen entity new --all # regenerate all entities
|
|
85
|
+
codegen entity new --dry-run # preview without writing
|
|
86
|
+
codegen entity list # tabular entity list
|
|
87
|
+
codegen entity validate [dir] # schema + cross-reference checks
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Subsystem Commands
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
codegen subsystem install events # domain event bus (transactional outbox)
|
|
94
|
+
codegen subsystem install jobs # background job queue (pg-boss pattern)
|
|
95
|
+
codegen subsystem install cache # key-value cache with TTL
|
|
96
|
+
codegen subsystem install storage # file storage (local filesystem)
|
|
97
|
+
codegen subsystem list # show installed + available
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Each subsystem generates a protocol (interface), Drizzle backend (Postgres), memory backend (tests), and a NestJS module with `forRoot({ backend })` factory.
|
|
101
|
+
|
|
102
|
+
### Project Commands
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
codegen init # scaffold a new consumer project
|
|
106
|
+
codegen project scan # detect conventions → propose config
|
|
107
|
+
codegen project config # view resolved config
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## What Gets Generated
|
|
111
|
+
|
|
112
|
+
**Clean Architecture** (default, `generate.architecture: clean`):
|
|
113
|
+
```
|
|
114
|
+
domain/{entity}/ Entity class + repository interface
|
|
115
|
+
application/commands/{entity}/ Create, Update, Delete use cases
|
|
116
|
+
application/queries/{entity}/ GetById, List, declarative queries
|
|
117
|
+
infrastructure/persistence/ Drizzle schema + repository impl
|
|
118
|
+
presentation/rest/ REST controller
|
|
119
|
+
modules/ NestJS module wiring
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Clean-Lite-PS** (`generate.architecture: clean-lite-ps`):
|
|
123
|
+
```
|
|
124
|
+
modules/{plural}/
|
|
125
|
+
{entity}.entity.ts Drizzle table + types
|
|
126
|
+
{entity}.repository.ts Extends family base class
|
|
127
|
+
{entity}.service.ts Extends family base service
|
|
128
|
+
{entity}.controller.ts REST endpoints
|
|
129
|
+
{plural}.module.ts NestJS module
|
|
130
|
+
dto/ Create, Update, Output DTOs
|
|
131
|
+
use-cases/ FindById, List, declarative queries
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Entity Families
|
|
135
|
+
|
|
136
|
+
Families provide pre-built base classes with domain-specific query patterns:
|
|
137
|
+
|
|
138
|
+
| Family | When to Use | Key Methods |
|
|
139
|
+
|--------|-------------|-------------|
|
|
140
|
+
| `synced` | CRM-synced entities (contacts, accounts) | `findByExternalId`, `syncUpsert`, `findAllByUserId` |
|
|
141
|
+
| `activity` | Time-based events (emails, calls, meetings) | `findByDateRange`, `findRecentByOpportunityId` |
|
|
142
|
+
| `metadata` | Key-value data (tags, custom fields) | `findByEntityIdAndType`, `upsertMany` |
|
|
143
|
+
| `knowledge` | Vector-searchable content | Stub (needs pgvector) |
|
|
144
|
+
| *(none)* | Generic CRUD | Base repository + service only |
|
|
145
|
+
|
|
146
|
+
## Declarative Queries
|
|
147
|
+
|
|
148
|
+
The `queries:` block generates typed repository methods, use case classes, and module registration:
|
|
149
|
+
|
|
150
|
+
```yaml
|
|
151
|
+
queries:
|
|
152
|
+
- by: [email] # → FindContactByEmailUseCase (unique)
|
|
153
|
+
unique: true
|
|
154
|
+
- by: [account_id] # → FindContactByAccountIdUseCase (ordered)
|
|
155
|
+
order: created_at desc
|
|
156
|
+
- by: [user_id, status] # → FindContactByUserIdAndStatusUseCase (compound)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Configuration
|
|
160
|
+
|
|
161
|
+
`codegen.config.yaml` in your project root:
|
|
162
|
+
|
|
163
|
+
```yaml
|
|
164
|
+
paths:
|
|
165
|
+
backend_src: src
|
|
166
|
+
entities_dir: entities
|
|
167
|
+
generated: src/generated
|
|
168
|
+
|
|
169
|
+
generate:
|
|
170
|
+
architecture: clean-lite-ps # clean | clean-lite-ps
|
|
171
|
+
frontend: false # default false; scanner detects apps/frontend/
|
|
172
|
+
commands: true
|
|
173
|
+
queries: true
|
|
174
|
+
|
|
175
|
+
naming:
|
|
176
|
+
fileCase: kebab-case
|
|
177
|
+
suffixStyle: dotted # .entity.ts vs Entity.ts
|
|
178
|
+
terminology:
|
|
179
|
+
command: use-case
|
|
180
|
+
query: use-case
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Auto-detect your project's conventions with `codegen project scan`.
|
|
184
|
+
|
|
185
|
+
## Using in Your Project
|
|
186
|
+
|
|
187
|
+
See [docs/CONSUMER-SETUP.md](docs/CONSUMER-SETUP.md) for the full consumer contract: tsconfig path aliases, `DatabaseModule` scaffold, runtime shims, and the one-time `app.module.ts` wire-up.
|
|
188
|
+
|
|
189
|
+
See [docs/GETTING-STARTED.md](docs/GETTING-STARTED.md) for a walkthrough of entity YAML authoring.
|
|
190
|
+
|
|
191
|
+
## Project Layout
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
src/ Generator source code
|
|
195
|
+
cli/ Clipanion CLI (noun-verb architecture)
|
|
196
|
+
analyzer/ Graph building, consistency checking
|
|
197
|
+
parser/ YAML loading, cross-reference resolution
|
|
198
|
+
scanner/ Project pattern detection
|
|
199
|
+
schema/ Zod validation schemas
|
|
200
|
+
behaviors/ Shared behaviors (timestamps, soft-delete)
|
|
201
|
+
config/ Config loader, paths, naming
|
|
202
|
+
formatters/ Console, JSON, markdown output
|
|
203
|
+
__tests__/ Unit tests (mirrors src/ structure)
|
|
204
|
+
runtime/ Code shipped into consumer projects
|
|
205
|
+
base-classes/ BaseRepository, BaseService, family bases
|
|
206
|
+
subsystems/ Events, Jobs, Cache, Storage
|
|
207
|
+
templates/ Hygen EJS templates
|
|
208
|
+
test/ Baseline snapshots, scaffold integration, smoke test
|
|
209
|
+
docs/ ADRs, consumer setup, getting started
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AggregationType, DimensionType, EntityType, MetricType, NonAdditiveDimensionConfig, SemanticFieldConfig, TimeGranularity } from './types.js';
|
|
2
|
+
export { CumulativeMetric, DerivedMetric, MetricDefinition, RatioMetric, SimpleMetric } from './metrics.js';
|
|
3
|
+
export { DimensionSpec, EntitySpec, MeasureSpec, SemanticModelSpec } from './specs.js';
|
|
4
|
+
export { MonetaryMeasures } from './packs/monetary-measures.js';
|
|
5
|
+
export { CrmEntityMeasures } from './packs/crm-entity-measures.js';
|
|
6
|
+
import '../subsystems/analytics/analytics-query.protocol.js';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// runtime/analytics/types.ts
|
|
2
|
+
var AggregationType = /* @__PURE__ */ ((AggregationType2) => {
|
|
3
|
+
AggregationType2["SUM"] = "sum";
|
|
4
|
+
AggregationType2["MIN"] = "min";
|
|
5
|
+
AggregationType2["MAX"] = "max";
|
|
6
|
+
AggregationType2["COUNT"] = "count";
|
|
7
|
+
AggregationType2["COUNT_DISTINCT"] = "count_distinct";
|
|
8
|
+
AggregationType2["AVERAGE"] = "average";
|
|
9
|
+
AggregationType2["MEDIAN"] = "median";
|
|
10
|
+
AggregationType2["PERCENTILE"] = "percentile";
|
|
11
|
+
AggregationType2["SUM_BOOLEAN"] = "sum_boolean";
|
|
12
|
+
return AggregationType2;
|
|
13
|
+
})(AggregationType || {});
|
|
14
|
+
var DimensionType = /* @__PURE__ */ ((DimensionType2) => {
|
|
15
|
+
DimensionType2["CATEGORICAL"] = "categorical";
|
|
16
|
+
DimensionType2["TIME"] = "time";
|
|
17
|
+
return DimensionType2;
|
|
18
|
+
})(DimensionType || {});
|
|
19
|
+
var EntityType = /* @__PURE__ */ ((EntityType2) => {
|
|
20
|
+
EntityType2["PRIMARY"] = "primary";
|
|
21
|
+
EntityType2["UNIQUE"] = "unique";
|
|
22
|
+
EntityType2["FOREIGN"] = "foreign";
|
|
23
|
+
EntityType2["NATURAL"] = "natural";
|
|
24
|
+
return EntityType2;
|
|
25
|
+
})(EntityType || {});
|
|
26
|
+
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
27
|
+
MetricType2["SIMPLE"] = "simple";
|
|
28
|
+
MetricType2["DERIVED"] = "derived";
|
|
29
|
+
MetricType2["RATIO"] = "ratio";
|
|
30
|
+
MetricType2["CUMULATIVE"] = "cumulative";
|
|
31
|
+
MetricType2["CONVERSION"] = "conversion";
|
|
32
|
+
return MetricType2;
|
|
33
|
+
})(MetricType || {});
|
|
34
|
+
var TimeGranularity = /* @__PURE__ */ ((TimeGranularity2) => {
|
|
35
|
+
TimeGranularity2["DAY"] = "day";
|
|
36
|
+
TimeGranularity2["WEEK"] = "week";
|
|
37
|
+
TimeGranularity2["MONTH"] = "month";
|
|
38
|
+
TimeGranularity2["QUARTER"] = "quarter";
|
|
39
|
+
TimeGranularity2["YEAR"] = "year";
|
|
40
|
+
return TimeGranularity2;
|
|
41
|
+
})(TimeGranularity || {});
|
|
42
|
+
export {
|
|
43
|
+
AggregationType,
|
|
44
|
+
DimensionType,
|
|
45
|
+
EntityType,
|
|
46
|
+
MetricType,
|
|
47
|
+
TimeGranularity
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../runtime/analytics/types.ts"],"sourcesContent":["/**\n * Semantic type definitions for the analytics layer.\n *\n * These types mirror MetricFlow / dbt-semantic-interfaces enums but are\n * defined locally so consumers don't need the full dependency for basic\n * field configuration. When the cube.js backend is used, these values\n * map 1:1 to cube measure/dimension types.\n */\n\n// ============================================================================\n// Enums\n// ============================================================================\n\nexport enum AggregationType {\n SUM = 'sum',\n MIN = 'min',\n MAX = 'max',\n COUNT = 'count',\n COUNT_DISTINCT = 'count_distinct',\n AVERAGE = 'average',\n MEDIAN = 'median',\n PERCENTILE = 'percentile',\n SUM_BOOLEAN = 'sum_boolean',\n}\n\nexport enum DimensionType {\n CATEGORICAL = 'categorical',\n TIME = 'time',\n}\n\nexport enum EntityType {\n PRIMARY = 'primary',\n UNIQUE = 'unique',\n FOREIGN = 'foreign',\n NATURAL = 'natural',\n}\n\nexport enum MetricType {\n SIMPLE = 'simple',\n DERIVED = 'derived',\n RATIO = 'ratio',\n CUMULATIVE = 'cumulative',\n CONVERSION = 'conversion',\n}\n\n/**\n * Time granularity for time dimensions.\n *\n * Sub-day granularities (hour, minute, second) are intentionally omitted\n * because cube.js does not support them.\n */\nexport enum TimeGranularity {\n DAY = 'day',\n WEEK = 'week',\n MONTH = 'month',\n QUARTER = 'quarter',\n YEAR = 'year',\n}\n\n// ============================================================================\n// Config interfaces\n// ============================================================================\n\n/**\n * Configuration for non-additive dimensions on measures.\n *\n * Non-additive dimensions specify that a measure cannot be summed across\n * certain dimensions. For example, inventory balances cannot be summed\n * across time — you need the latest value, not the sum.\n */\nexport interface NonAdditiveDimensionConfig {\n name: string;\n window_choice?: AggregationType;\n window_groupings?: string[];\n}\n\n/**\n * Complete semantic configuration for a field.\n *\n * Used to store all semantic metadata on a field definition for later\n * extraction by the manifest builder / cube schema generator.\n */\nexport interface SemanticFieldConfig {\n // Measure configuration\n measure?: boolean;\n agg?: AggregationType;\n agg_time_dimension?: string;\n non_additive_dimension?: NonAdditiveDimensionConfig;\n\n // Dimension configuration\n dimension?: boolean;\n dimension_type?: DimensionType;\n time_granularity?: TimeGranularity;\n is_partition?: boolean;\n\n // Entity configuration\n entity?: boolean;\n entity_type?: EntityType;\n entity_role?: string;\n\n // Common\n semantic_expr?: string;\n semantic_label?: string;\n visibility?: 'internal' | 'agent' | 'public';\n}\n"],"mappings":";AAaO,IAAK,kBAAL,kBAAKA,qBAAL;AACL,EAAAA,iBAAA,SAAM;AACN,EAAAA,iBAAA,SAAM;AACN,EAAAA,iBAAA,SAAM;AACN,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,YAAS;AACT,EAAAA,iBAAA,gBAAa;AACb,EAAAA,iBAAA,iBAAc;AATJ,SAAAA;AAAA,GAAA;AAYL,IAAK,gBAAL,kBAAKC,mBAAL;AACL,EAAAA,eAAA,iBAAc;AACd,EAAAA,eAAA,UAAO;AAFG,SAAAA;AAAA,GAAA;AAKL,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AAJA,SAAAA;AAAA,GAAA;AAOL,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AALH,SAAAA;AAAA,GAAA;AAcL,IAAK,kBAAL,kBAAKC,qBAAL;AACL,EAAAA,iBAAA,SAAM;AACN,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,UAAO;AALG,SAAAA;AAAA,GAAA;","names":["AggregationType","DimensionType","EntityType","MetricType","TimeGranularity"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { TimeGranularity, AggregationType } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Metric composition types for the analytics layer.
|
|
5
|
+
*
|
|
6
|
+
* Ported from the Python reference (pattern_stack/atoms/semantic/metrics.py).
|
|
7
|
+
* These interfaces describe the four metric types that can be declared on
|
|
8
|
+
* entity YAML specs and compiled into cube.js metric definitions.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A simple metric based on a single measure.
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
* { type: 'simple', measure: 'amount' }
|
|
16
|
+
* { type: 'simple', measure: 'amount', agg: 'count', filter: "status = 'completed'" }
|
|
17
|
+
*/
|
|
18
|
+
interface SimpleMetric {
|
|
19
|
+
type: 'simple';
|
|
20
|
+
measure: string;
|
|
21
|
+
agg?: AggregationType;
|
|
22
|
+
filter?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A derived metric computed from an expression over other metrics.
|
|
28
|
+
*
|
|
29
|
+
* Example:
|
|
30
|
+
* { type: 'derived', expr: 'total_revenue / order_count', metrics: ['total_revenue', 'order_count'] }
|
|
31
|
+
*/
|
|
32
|
+
interface DerivedMetric {
|
|
33
|
+
type: 'derived';
|
|
34
|
+
expr: string;
|
|
35
|
+
metrics: string[];
|
|
36
|
+
description?: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A ratio metric computing numerator / denominator.
|
|
41
|
+
*
|
|
42
|
+
* Example:
|
|
43
|
+
* { type: 'ratio', numerator: 'won_deals', denominator: 'total_deals' }
|
|
44
|
+
*/
|
|
45
|
+
interface RatioMetric {
|
|
46
|
+
type: 'ratio';
|
|
47
|
+
numerator: string | SimpleMetric;
|
|
48
|
+
denominator: string | SimpleMetric;
|
|
49
|
+
filter?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
label?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A cumulative metric for time-series accumulation.
|
|
55
|
+
*
|
|
56
|
+
* Specify either window OR grain_to_date, not both.
|
|
57
|
+
*
|
|
58
|
+
* Example:
|
|
59
|
+
* { type: 'cumulative', measure: 'revenue', window: '28 days' }
|
|
60
|
+
* { type: 'cumulative', measure: 'order_count', grain_to_date: 'month' }
|
|
61
|
+
*/
|
|
62
|
+
interface CumulativeMetric {
|
|
63
|
+
type: 'cumulative';
|
|
64
|
+
measure: string;
|
|
65
|
+
window?: string;
|
|
66
|
+
grain_to_date?: TimeGranularity;
|
|
67
|
+
description?: string;
|
|
68
|
+
label?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Union type of all metric definitions.
|
|
72
|
+
*/
|
|
73
|
+
type MetricDefinition = SimpleMetric | DerivedMetric | RatioMetric | CumulativeMetric;
|
|
74
|
+
|
|
75
|
+
export type { CumulativeMetric, DerivedMetric, MetricDefinition, RatioMetric, SimpleMetric };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AnalyticsQueryOpts, ResultRow } from '../../subsystems/analytics/analytics-query.protocol.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CrmEntityMeasures — measure pack interface for CRM entities.
|
|
5
|
+
*
|
|
6
|
+
* Entities that include the 'crm_entity' measure pack implement this
|
|
7
|
+
* interface on their generated analytics provider.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface CrmEntityMeasures {
|
|
11
|
+
/**
|
|
12
|
+
* Count of active (non-deleted) entities.
|
|
13
|
+
*/
|
|
14
|
+
activeCount(opts?: AnalyticsQueryOpts): Promise<ResultRow[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Count of entities created in the last N days.
|
|
17
|
+
*/
|
|
18
|
+
createdInLastNDays(n: number, opts?: AnalyticsQueryOpts): Promise<ResultRow[]>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type { CrmEntityMeasures };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=crm-entity-measures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AnalyticsQueryOpts, ResultRow } from '../../subsystems/analytics/analytics-query.protocol.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MonetaryMeasures — measure pack interface for revenue / monetary fields.
|
|
5
|
+
*
|
|
6
|
+
* Entities that include the 'monetary' measure pack implement this interface
|
|
7
|
+
* on their generated analytics provider.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface MonetaryMeasures {
|
|
11
|
+
/**
|
|
12
|
+
* Total revenue (sum of the monetary measure).
|
|
13
|
+
*/
|
|
14
|
+
totalRevenue(opts?: AnalyticsQueryOpts): Promise<ResultRow[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Revenue broken down by a dimension.
|
|
17
|
+
*/
|
|
18
|
+
revenueBy(dimension: string, opts?: AnalyticsQueryOpts): Promise<ResultRow[]>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type { MonetaryMeasures };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=monetary-measures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DimensionType, TimeGranularity, EntityType, AggregationType, NonAdditiveDimensionConfig } from './types.js';
|
|
2
|
+
import { MetricDefinition } from './metrics.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Intermediate spec types for the analytics layer.
|
|
6
|
+
*
|
|
7
|
+
* Ported from the Python reference (pattern_stack/atoms/semantic/manifest.py).
|
|
8
|
+
* These interfaces are the intermediate representation used when extracting
|
|
9
|
+
* semantic metadata from entity YAML and converting it into cube.js schema.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface MeasureSpec {
|
|
13
|
+
name: string;
|
|
14
|
+
agg: AggregationType;
|
|
15
|
+
expr?: string;
|
|
16
|
+
agg_time_dimension?: string;
|
|
17
|
+
non_additive_dimension?: NonAdditiveDimensionConfig;
|
|
18
|
+
description?: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
}
|
|
21
|
+
interface DimensionSpec {
|
|
22
|
+
name: string;
|
|
23
|
+
dimension_type: DimensionType;
|
|
24
|
+
expr?: string;
|
|
25
|
+
time_granularity?: TimeGranularity;
|
|
26
|
+
is_partition?: boolean;
|
|
27
|
+
description?: string;
|
|
28
|
+
label?: string;
|
|
29
|
+
}
|
|
30
|
+
interface EntitySpec {
|
|
31
|
+
name: string;
|
|
32
|
+
entity_type: EntityType;
|
|
33
|
+
expr?: string;
|
|
34
|
+
role?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
label?: string;
|
|
37
|
+
}
|
|
38
|
+
interface SemanticModelSpec {
|
|
39
|
+
name: string;
|
|
40
|
+
table_name: string;
|
|
41
|
+
measures: MeasureSpec[];
|
|
42
|
+
dimensions: DimensionSpec[];
|
|
43
|
+
entities: EntitySpec[];
|
|
44
|
+
metrics: MetricDefinition[];
|
|
45
|
+
primary_entity?: string;
|
|
46
|
+
default_agg_time_dimension?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type { DimensionSpec, EntitySpec, MeasureSpec, SemanticModelSpec };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=specs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic type definitions for the analytics layer.
|
|
3
|
+
*
|
|
4
|
+
* These types mirror MetricFlow / dbt-semantic-interfaces enums but are
|
|
5
|
+
* defined locally so consumers don't need the full dependency for basic
|
|
6
|
+
* field configuration. When the cube.js backend is used, these values
|
|
7
|
+
* map 1:1 to cube measure/dimension types.
|
|
8
|
+
*/
|
|
9
|
+
declare enum AggregationType {
|
|
10
|
+
SUM = "sum",
|
|
11
|
+
MIN = "min",
|
|
12
|
+
MAX = "max",
|
|
13
|
+
COUNT = "count",
|
|
14
|
+
COUNT_DISTINCT = "count_distinct",
|
|
15
|
+
AVERAGE = "average",
|
|
16
|
+
MEDIAN = "median",
|
|
17
|
+
PERCENTILE = "percentile",
|
|
18
|
+
SUM_BOOLEAN = "sum_boolean"
|
|
19
|
+
}
|
|
20
|
+
declare enum DimensionType {
|
|
21
|
+
CATEGORICAL = "categorical",
|
|
22
|
+
TIME = "time"
|
|
23
|
+
}
|
|
24
|
+
declare enum EntityType {
|
|
25
|
+
PRIMARY = "primary",
|
|
26
|
+
UNIQUE = "unique",
|
|
27
|
+
FOREIGN = "foreign",
|
|
28
|
+
NATURAL = "natural"
|
|
29
|
+
}
|
|
30
|
+
declare enum MetricType {
|
|
31
|
+
SIMPLE = "simple",
|
|
32
|
+
DERIVED = "derived",
|
|
33
|
+
RATIO = "ratio",
|
|
34
|
+
CUMULATIVE = "cumulative",
|
|
35
|
+
CONVERSION = "conversion"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Time granularity for time dimensions.
|
|
39
|
+
*
|
|
40
|
+
* Sub-day granularities (hour, minute, second) are intentionally omitted
|
|
41
|
+
* because cube.js does not support them.
|
|
42
|
+
*/
|
|
43
|
+
declare enum TimeGranularity {
|
|
44
|
+
DAY = "day",
|
|
45
|
+
WEEK = "week",
|
|
46
|
+
MONTH = "month",
|
|
47
|
+
QUARTER = "quarter",
|
|
48
|
+
YEAR = "year"
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for non-additive dimensions on measures.
|
|
52
|
+
*
|
|
53
|
+
* Non-additive dimensions specify that a measure cannot be summed across
|
|
54
|
+
* certain dimensions. For example, inventory balances cannot be summed
|
|
55
|
+
* across time — you need the latest value, not the sum.
|
|
56
|
+
*/
|
|
57
|
+
interface NonAdditiveDimensionConfig {
|
|
58
|
+
name: string;
|
|
59
|
+
window_choice?: AggregationType;
|
|
60
|
+
window_groupings?: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Complete semantic configuration for a field.
|
|
64
|
+
*
|
|
65
|
+
* Used to store all semantic metadata on a field definition for later
|
|
66
|
+
* extraction by the manifest builder / cube schema generator.
|
|
67
|
+
*/
|
|
68
|
+
interface SemanticFieldConfig {
|
|
69
|
+
measure?: boolean;
|
|
70
|
+
agg?: AggregationType;
|
|
71
|
+
agg_time_dimension?: string;
|
|
72
|
+
non_additive_dimension?: NonAdditiveDimensionConfig;
|
|
73
|
+
dimension?: boolean;
|
|
74
|
+
dimension_type?: DimensionType;
|
|
75
|
+
time_granularity?: TimeGranularity;
|
|
76
|
+
is_partition?: boolean;
|
|
77
|
+
entity?: boolean;
|
|
78
|
+
entity_type?: EntityType;
|
|
79
|
+
entity_role?: string;
|
|
80
|
+
semantic_expr?: string;
|
|
81
|
+
semantic_label?: string;
|
|
82
|
+
visibility?: 'internal' | 'agent' | 'public';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { AggregationType, DimensionType, EntityType, MetricType, type NonAdditiveDimensionConfig, type SemanticFieldConfig, TimeGranularity };
|