@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,617 @@
|
|
|
1
|
+
// runtime/base-classes/base-repository.ts
|
|
2
|
+
import { eq, inArray, isNull, sql } from "drizzle-orm";
|
|
3
|
+
var BaseRepository = class {
|
|
4
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
5
|
+
/**
|
|
6
|
+
* Behavior flags controlling automatic behavior injection.
|
|
7
|
+
* Override in concrete repositories to enable behaviors.
|
|
8
|
+
*/
|
|
9
|
+
behaviors = {
|
|
10
|
+
timestamps: false,
|
|
11
|
+
softDelete: false,
|
|
12
|
+
userTracking: false
|
|
13
|
+
};
|
|
14
|
+
db;
|
|
15
|
+
constructor(db) {
|
|
16
|
+
this.db = db;
|
|
17
|
+
}
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Read Operations
|
|
20
|
+
// ============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* Find a single entity by its primary key.
|
|
23
|
+
* Returns null if not found (or soft-deleted when softDelete=true).
|
|
24
|
+
*/
|
|
25
|
+
async findById(id) {
|
|
26
|
+
const rows = await this.baseQuery().where(eq(this.table["id"], id)).limit(1);
|
|
27
|
+
return rows[0] ?? null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Find multiple entities by their primary keys.
|
|
31
|
+
* Returns empty array immediately for empty input (avoids DB errors).
|
|
32
|
+
*/
|
|
33
|
+
async findByIds(ids) {
|
|
34
|
+
if (ids.length === 0) return [];
|
|
35
|
+
const rows = await this.baseQuery().where(inArray(this.table["id"], ids));
|
|
36
|
+
return rows;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* List entities with optional filtering, pagination, and ordering.
|
|
40
|
+
*/
|
|
41
|
+
async list(options) {
|
|
42
|
+
let query = this.baseQuery();
|
|
43
|
+
if (options?.where) {
|
|
44
|
+
query = query.where(options.where);
|
|
45
|
+
}
|
|
46
|
+
if (options?.orderBy) {
|
|
47
|
+
query = query.orderBy(options.orderBy);
|
|
48
|
+
}
|
|
49
|
+
if (options?.limit !== void 0) {
|
|
50
|
+
query = query.limit(options.limit);
|
|
51
|
+
}
|
|
52
|
+
if (options?.offset !== void 0) {
|
|
53
|
+
query = query.offset(options.offset);
|
|
54
|
+
}
|
|
55
|
+
const rows = await query;
|
|
56
|
+
return rows;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Count entities matching an optional WHERE clause.
|
|
60
|
+
* Soft-deleted rows are always excluded when softDelete=true.
|
|
61
|
+
*/
|
|
62
|
+
async count(where) {
|
|
63
|
+
let query = this.db.select({ count: sql`cast(count(*) as integer)` }).from(this.table);
|
|
64
|
+
const conditions = [];
|
|
65
|
+
if (this.behaviors.softDelete) {
|
|
66
|
+
conditions.push(isNull(this.table["deletedAt"]));
|
|
67
|
+
}
|
|
68
|
+
if (where) {
|
|
69
|
+
conditions.push(where);
|
|
70
|
+
}
|
|
71
|
+
if (conditions.length === 1) {
|
|
72
|
+
query = query.where(conditions[0]);
|
|
73
|
+
} else if (conditions.length > 1) {
|
|
74
|
+
const { and: and2 } = await import("drizzle-orm");
|
|
75
|
+
query = query.where(and2(...conditions));
|
|
76
|
+
}
|
|
77
|
+
const rows = await query;
|
|
78
|
+
return rows[0]?.count ?? 0;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Check whether an entity with the given id exists.
|
|
82
|
+
*/
|
|
83
|
+
async exists(id) {
|
|
84
|
+
const result = await this.findById(id);
|
|
85
|
+
return result !== null;
|
|
86
|
+
}
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// Write Operations
|
|
89
|
+
// ============================================================================
|
|
90
|
+
/**
|
|
91
|
+
* Insert a new entity. Timestamps are auto-injected when timestamps=true.
|
|
92
|
+
*/
|
|
93
|
+
async create(input) {
|
|
94
|
+
const data = this.withTimestamps(input, "create");
|
|
95
|
+
const rows = await this.db.insert(this.table).values(data).returning();
|
|
96
|
+
return rows[0];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Update an existing entity by id. updatedAt is auto-injected when timestamps=true.
|
|
100
|
+
* Returns the updated entity.
|
|
101
|
+
*/
|
|
102
|
+
async update(id, input) {
|
|
103
|
+
const data = this.withTimestamps(input, "update");
|
|
104
|
+
const rows = await this.db.update(this.table).set(data).where(eq(this.table["id"], id)).returning();
|
|
105
|
+
return rows[0];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Delete an entity by id.
|
|
109
|
+
* - softDelete=true: sets deletedAt to current timestamp
|
|
110
|
+
* - softDelete=false: hard-deletes the row
|
|
111
|
+
*/
|
|
112
|
+
async delete(id) {
|
|
113
|
+
if (this.behaviors.softDelete) {
|
|
114
|
+
await this.db.update(this.table).set({ deletedAt: /* @__PURE__ */ new Date() }).where(eq(this.table["id"], id));
|
|
115
|
+
} else {
|
|
116
|
+
await this.db.delete(this.table).where(eq(this.table["id"], id));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Insert or update multiple entities.
|
|
121
|
+
* Default naive implementation — family repositories override with
|
|
122
|
+
* proper conflict-target upsert (e.g., CrmEntityRepository).
|
|
123
|
+
*/
|
|
124
|
+
async upsertMany(inputs) {
|
|
125
|
+
return Promise.all(inputs.map((input) => this.create(input)));
|
|
126
|
+
}
|
|
127
|
+
// ============================================================================
|
|
128
|
+
// Protected Helpers
|
|
129
|
+
// ============================================================================
|
|
130
|
+
/**
|
|
131
|
+
* Base SELECT query that automatically excludes soft-deleted rows
|
|
132
|
+
* when softDelete behavior is enabled.
|
|
133
|
+
*/
|
|
134
|
+
baseQuery() {
|
|
135
|
+
const query = this.db.select().from(this.table).$dynamic();
|
|
136
|
+
if (this.behaviors.softDelete) {
|
|
137
|
+
return query.where(isNull(this.table["deletedAt"]));
|
|
138
|
+
}
|
|
139
|
+
return query;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Merge timestamp fields into an input object.
|
|
143
|
+
* - mode='create': adds createdAt and updatedAt
|
|
144
|
+
* - mode='update': adds updatedAt only
|
|
145
|
+
*
|
|
146
|
+
* No-op when timestamps behavior is disabled.
|
|
147
|
+
*/
|
|
148
|
+
withTimestamps(input, mode) {
|
|
149
|
+
if (!this.behaviors.timestamps) return input;
|
|
150
|
+
const now = /* @__PURE__ */ new Date();
|
|
151
|
+
if (mode === "create") {
|
|
152
|
+
return { ...input, createdAt: now, updatedAt: now };
|
|
153
|
+
}
|
|
154
|
+
return { ...input, updatedAt: now };
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// runtime/base-classes/lifecycle-events.ts
|
|
159
|
+
import { randomUUID } from "crypto";
|
|
160
|
+
var SYSTEM_FIELDS = /* @__PURE__ */ new Set([
|
|
161
|
+
"id",
|
|
162
|
+
"createdAt",
|
|
163
|
+
"updatedAt",
|
|
164
|
+
"deletedAt"
|
|
165
|
+
]);
|
|
166
|
+
function entitySnapshot(entity) {
|
|
167
|
+
const snap = {};
|
|
168
|
+
for (const [key, value] of Object.entries(entity)) {
|
|
169
|
+
if (!SYSTEM_FIELDS.has(key)) {
|
|
170
|
+
snap[key] = value;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return snap;
|
|
174
|
+
}
|
|
175
|
+
function diffSnapshots(before, after) {
|
|
176
|
+
const changes = [];
|
|
177
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
178
|
+
for (const key of allKeys) {
|
|
179
|
+
if (SYSTEM_FIELDS.has(key)) continue;
|
|
180
|
+
const oldVal = before[key];
|
|
181
|
+
const newVal = after[key];
|
|
182
|
+
if (oldVal !== newVal && JSON.stringify(oldVal) !== JSON.stringify(newVal)) {
|
|
183
|
+
changes.push({ field: key, oldValue: oldVal, newValue: newVal });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return changes;
|
|
187
|
+
}
|
|
188
|
+
function buildLifecycleEvent(entityName, action, entityId, snapshot) {
|
|
189
|
+
return {
|
|
190
|
+
id: randomUUID(),
|
|
191
|
+
type: `${entityName}.${action}`,
|
|
192
|
+
aggregateId: entityId,
|
|
193
|
+
aggregateType: entityName,
|
|
194
|
+
payload: snapshot ? { snapshot } : {},
|
|
195
|
+
occurredAt: /* @__PURE__ */ new Date(),
|
|
196
|
+
metadata: { category: "lifecycle" }
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function buildChangeEvents(entityName, entityId, changes) {
|
|
200
|
+
return changes.map((c) => ({
|
|
201
|
+
id: randomUUID(),
|
|
202
|
+
type: `${entityName}.field_changed`,
|
|
203
|
+
aggregateId: entityId,
|
|
204
|
+
aggregateType: entityName,
|
|
205
|
+
payload: {
|
|
206
|
+
fieldName: c.field,
|
|
207
|
+
oldValue: c.oldValue,
|
|
208
|
+
newValue: c.newValue
|
|
209
|
+
},
|
|
210
|
+
occurredAt: /* @__PURE__ */ new Date(),
|
|
211
|
+
metadata: { category: "change" }
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
async function emitSafely(eventBus, events) {
|
|
215
|
+
if (!eventBus || events.length === 0) return;
|
|
216
|
+
try {
|
|
217
|
+
if (events.length === 1) {
|
|
218
|
+
await eventBus.publish(events[0]);
|
|
219
|
+
} else {
|
|
220
|
+
await eventBus.publishMany(events);
|
|
221
|
+
}
|
|
222
|
+
} catch {
|
|
223
|
+
console.warn(`[lifecycle-events] failed to emit ${events.length} event(s)`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// runtime/base-classes/base-service.ts
|
|
228
|
+
var BaseService = class {
|
|
229
|
+
constructor(repository) {
|
|
230
|
+
this.repository = repository;
|
|
231
|
+
}
|
|
232
|
+
repository;
|
|
233
|
+
/**
|
|
234
|
+
* Entity name for event types (e.g., 'account' → 'account.created').
|
|
235
|
+
* Set by generated services. If empty, lifecycle events are skipped.
|
|
236
|
+
*/
|
|
237
|
+
entityName;
|
|
238
|
+
/**
|
|
239
|
+
* Event bus for lifecycle/change event emission.
|
|
240
|
+
* Injected via @Inject(EVENT_BUS) @Optional() on generated services.
|
|
241
|
+
* If undefined (no events subsystem installed), emission is silently skipped.
|
|
242
|
+
*/
|
|
243
|
+
eventBus;
|
|
244
|
+
/**
|
|
245
|
+
* Whether to emit lifecycle events. Default: true.
|
|
246
|
+
* Override to false in entity YAML via behaviors or in the service class.
|
|
247
|
+
*/
|
|
248
|
+
emitLifecycleEvents = true;
|
|
249
|
+
/**
|
|
250
|
+
* Find a single entity by its primary key.
|
|
251
|
+
* Returns null if not found.
|
|
252
|
+
*/
|
|
253
|
+
findById(id) {
|
|
254
|
+
return this.repository.findById(id);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Find multiple entities by their primary keys.
|
|
258
|
+
*/
|
|
259
|
+
findByIds(ids) {
|
|
260
|
+
return this.repository.findByIds(ids);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* List entities with optional filtering/pagination options.
|
|
264
|
+
*/
|
|
265
|
+
list(options) {
|
|
266
|
+
return this.repository.list(options);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Count entities matching an optional filter.
|
|
270
|
+
*/
|
|
271
|
+
count(where) {
|
|
272
|
+
return this.repository.count(where);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Check whether an entity with the given id exists.
|
|
276
|
+
*/
|
|
277
|
+
exists(id) {
|
|
278
|
+
return this.repository.exists(id);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Insert a new entity.
|
|
282
|
+
* Emits a LIFECYCLE 'created' event with entity snapshot.
|
|
283
|
+
*/
|
|
284
|
+
async create(input) {
|
|
285
|
+
const result = await this.repository.create(input);
|
|
286
|
+
if (this._shouldEmit()) {
|
|
287
|
+
const snap = entitySnapshot(result);
|
|
288
|
+
const id = result.id;
|
|
289
|
+
const event = buildLifecycleEvent(this.entityName, "created", id, snap);
|
|
290
|
+
void emitSafely(this.eventBus, [event]);
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Update an existing entity by id.
|
|
296
|
+
* Emits a LIFECYCLE 'updated' event + CHANGE events for each modified field.
|
|
297
|
+
*/
|
|
298
|
+
async update(id, input) {
|
|
299
|
+
let before;
|
|
300
|
+
if (this._shouldEmit()) {
|
|
301
|
+
const existing = await this.repository.findById(id);
|
|
302
|
+
if (existing) {
|
|
303
|
+
before = entitySnapshot(existing);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const result = await this.repository.update(id, input);
|
|
307
|
+
if (this._shouldEmit()) {
|
|
308
|
+
const after = entitySnapshot(result);
|
|
309
|
+
const events = [
|
|
310
|
+
buildLifecycleEvent(this.entityName, "updated", id, after)
|
|
311
|
+
];
|
|
312
|
+
if (before) {
|
|
313
|
+
const changes = diffSnapshots(before, after);
|
|
314
|
+
if (changes.length > 0) {
|
|
315
|
+
events.push(...buildChangeEvents(this.entityName, id, changes));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
void emitSafely(this.eventBus, events);
|
|
319
|
+
}
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Delete an entity by id.
|
|
324
|
+
* Emits a LIFECYCLE 'deleted' event.
|
|
325
|
+
*/
|
|
326
|
+
async delete(id) {
|
|
327
|
+
await this.repository.delete(id);
|
|
328
|
+
if (this._shouldEmit()) {
|
|
329
|
+
const event = buildLifecycleEvent(this.entityName, "deleted", id);
|
|
330
|
+
void emitSafely(this.eventBus, [event]);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/** Check whether lifecycle event emission is active. */
|
|
334
|
+
_shouldEmit() {
|
|
335
|
+
return Boolean(
|
|
336
|
+
this.emitLifecycleEvents && this.entityName && this.eventBus
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// runtime/base-classes/base-read-use-cases.ts
|
|
342
|
+
var BaseFindByIdUseCase = class {
|
|
343
|
+
constructor(service) {
|
|
344
|
+
this.service = service;
|
|
345
|
+
}
|
|
346
|
+
service;
|
|
347
|
+
/**
|
|
348
|
+
* Find a single entity by its primary key.
|
|
349
|
+
* Returns null if not found.
|
|
350
|
+
*/
|
|
351
|
+
execute(id) {
|
|
352
|
+
return this.service.findById(id);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var BaseListUseCase = class {
|
|
356
|
+
constructor(service) {
|
|
357
|
+
this.service = service;
|
|
358
|
+
}
|
|
359
|
+
service;
|
|
360
|
+
/**
|
|
361
|
+
* List all entities (no filters).
|
|
362
|
+
* Controllers that need filtered lists should use a dedicated use case.
|
|
363
|
+
*/
|
|
364
|
+
execute() {
|
|
365
|
+
return this.service.list();
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// runtime/base-classes/synced-entity-repository.ts
|
|
370
|
+
import { eq as eq2, inArray as inArray2 } from "drizzle-orm";
|
|
371
|
+
var SyncedEntityRepository = class extends BaseRepository {
|
|
372
|
+
/**
|
|
373
|
+
* Find a single entity by its external CRM identifier.
|
|
374
|
+
*/
|
|
375
|
+
async findByExternalId(externalId) {
|
|
376
|
+
const rows = await this.baseQuery().where(eq2(this.table["externalId"], externalId)).limit(1);
|
|
377
|
+
return rows[0] ?? null;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Find multiple entities by external CRM identifiers.
|
|
381
|
+
*/
|
|
382
|
+
async findManyByExternalIds(externalIds) {
|
|
383
|
+
if (externalIds.length === 0) return [];
|
|
384
|
+
const rows = await this.baseQuery().where(inArray2(this.table["externalId"], externalIds));
|
|
385
|
+
return rows;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Find all entities owned by a specific user.
|
|
389
|
+
*/
|
|
390
|
+
async findAllByUserId(userId) {
|
|
391
|
+
const rows = await this.baseQuery().where(eq2(this.table["userId"], userId));
|
|
392
|
+
return rows;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Sync upsert — bulk insert-or-update from external CRM data.
|
|
396
|
+
* Concrete repositories must implement with the appropriate conflict target.
|
|
397
|
+
*/
|
|
398
|
+
async syncUpsert(_inputs) {
|
|
399
|
+
throw new Error("syncUpsert not implemented \u2014 override in concrete repository");
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Find entities visible to a user (ownership + sharing rules).
|
|
403
|
+
* Concrete repositories must implement with visibility logic.
|
|
404
|
+
*/
|
|
405
|
+
async findVisibleByUserId(_userId) {
|
|
406
|
+
throw new Error("findVisibleByUserId not implemented \u2014 override in concrete repository");
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// runtime/base-classes/activity-entity-repository.ts
|
|
411
|
+
import { eq as eq3, between, desc } from "drizzle-orm";
|
|
412
|
+
var ActivityEntityRepository = class extends BaseRepository {
|
|
413
|
+
/**
|
|
414
|
+
* Find activities within a date range (inclusive).
|
|
415
|
+
*/
|
|
416
|
+
async findByDateRange(start, end) {
|
|
417
|
+
const rows = await this.baseQuery().where(between(this.table["occurredAt"], start, end));
|
|
418
|
+
return rows;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Find all activities for a specific user.
|
|
422
|
+
*/
|
|
423
|
+
async findByUserId(userId) {
|
|
424
|
+
const rows = await this.baseQuery().where(eq3(this.table["userId"], userId));
|
|
425
|
+
return rows;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Find all activities for a specific opportunity.
|
|
429
|
+
*/
|
|
430
|
+
async findByOpportunityId(opportunityId) {
|
|
431
|
+
const rows = await this.baseQuery().where(eq3(this.table["opportunityId"], opportunityId));
|
|
432
|
+
return rows;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Find the most recent activities for an opportunity, ordered by occurredAt desc.
|
|
436
|
+
*/
|
|
437
|
+
async findRecentByOpportunityId(opportunityId, limit = 10) {
|
|
438
|
+
const rows = await this.baseQuery().where(eq3(this.table["opportunityId"], opportunityId)).orderBy(desc(this.table["occurredAt"])).limit(limit);
|
|
439
|
+
return rows;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// runtime/base-classes/metadata-entity-repository.ts
|
|
444
|
+
import { eq as eq4, and, desc as desc2 } from "drizzle-orm";
|
|
445
|
+
var MetadataEntityRepository = class extends BaseRepository {
|
|
446
|
+
/**
|
|
447
|
+
* Bulk upsert with a caller-specified conflict target.
|
|
448
|
+
* Uses Drizzle's onConflictDoUpdate to merge records.
|
|
449
|
+
*/
|
|
450
|
+
async upsertMany(inputs, conflictTarget) {
|
|
451
|
+
if (inputs.length === 0) return [];
|
|
452
|
+
if (!conflictTarget) {
|
|
453
|
+
return super.upsertMany(inputs);
|
|
454
|
+
}
|
|
455
|
+
const data = inputs.map(
|
|
456
|
+
(input) => this.withTimestamps(input, "create")
|
|
457
|
+
);
|
|
458
|
+
const rows = await this.db.insert(this.table).values(data).onConflictDoUpdate({
|
|
459
|
+
target: this.table[conflictTarget],
|
|
460
|
+
set: data[0]
|
|
461
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
462
|
+
}).returning();
|
|
463
|
+
return rows;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Find metadata by entity ID and entity type (compound lookup).
|
|
467
|
+
*/
|
|
468
|
+
async findByEntityIdAndType(entityId, entityType) {
|
|
469
|
+
const rows = await this.baseQuery().where(
|
|
470
|
+
and(
|
|
471
|
+
eq4(this.table["entityId"], entityId),
|
|
472
|
+
eq4(this.table["entityType"], entityType)
|
|
473
|
+
)
|
|
474
|
+
);
|
|
475
|
+
return rows;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* List all metadata records for an entity.
|
|
479
|
+
*/
|
|
480
|
+
async listByEntityId(entityId) {
|
|
481
|
+
const rows = await this.baseQuery().where(eq4(this.table["entityId"], entityId));
|
|
482
|
+
return rows;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* List metadata history for an entity, ordered by validFrom descending.
|
|
486
|
+
*/
|
|
487
|
+
async listHistoryByEntityId(entityId) {
|
|
488
|
+
const rows = await this.baseQuery().where(eq4(this.table["entityId"], entityId)).orderBy(desc2(this.table["validFrom"]));
|
|
489
|
+
return rows;
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// runtime/base-classes/knowledge-entity-repository.ts
|
|
494
|
+
var KnowledgeEntityRepository = class extends BaseRepository {
|
|
495
|
+
// pgvector-dependent methods will be added when the extension is available:
|
|
496
|
+
// semanticSearch, findPendingByOpportunityId, updateStatus, updateStatusBatch
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// runtime/base-classes/synced-entity-service.ts
|
|
500
|
+
var SyncedEntityService = class extends BaseService {
|
|
501
|
+
/**
|
|
502
|
+
* Find a single entity by its external CRM identifier.
|
|
503
|
+
*/
|
|
504
|
+
findByExternalId(externalId) {
|
|
505
|
+
return this.repository.findByExternalId(externalId);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Find multiple entities by external CRM identifiers.
|
|
509
|
+
*/
|
|
510
|
+
findManyByExternalIds(externalIds) {
|
|
511
|
+
return this.repository.findManyByExternalIds(externalIds);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Find all entities owned by a specific user.
|
|
515
|
+
*/
|
|
516
|
+
findAllByUser(userId) {
|
|
517
|
+
return this.repository.findAllByUserId(userId);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Find entities visible to a user (ownership + sharing rules).
|
|
521
|
+
* Concrete services may override with domain-specific visibility logic.
|
|
522
|
+
*/
|
|
523
|
+
findVisibleByUser(userId) {
|
|
524
|
+
return this.repository.findVisibleByUserId(userId);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// runtime/base-classes/activity-entity-service.ts
|
|
529
|
+
var ActivityEntityService = class extends BaseService {
|
|
530
|
+
/**
|
|
531
|
+
* Find activities within a date range (inclusive).
|
|
532
|
+
*/
|
|
533
|
+
findByDateRange(start, end) {
|
|
534
|
+
return this.repository.findByDateRange(start, end);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Find all activities for a specific user.
|
|
538
|
+
*/
|
|
539
|
+
findByUser(userId) {
|
|
540
|
+
return this.repository.findByUserId(userId);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Find all activities for a specific opportunity.
|
|
544
|
+
*/
|
|
545
|
+
findByOpportunity(opportunityId) {
|
|
546
|
+
return this.repository.findByOpportunityId(opportunityId);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Find the most recent activities for an opportunity.
|
|
550
|
+
*/
|
|
551
|
+
findRecent(opportunityId, limit) {
|
|
552
|
+
return this.repository.findRecentByOpportunityId(opportunityId, limit);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// runtime/base-classes/metadata-entity-service.ts
|
|
557
|
+
var MetadataEntityService = class extends BaseService {
|
|
558
|
+
/**
|
|
559
|
+
* Find metadata records by entity ID and entity type (EAV polymorphic lookup).
|
|
560
|
+
*/
|
|
561
|
+
findByEntityIdAndType(entityId, entityType) {
|
|
562
|
+
return this.repository.findByEntityIdAndType(entityId, entityType);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* List all metadata records for an entity.
|
|
566
|
+
*/
|
|
567
|
+
listByEntity(entityId) {
|
|
568
|
+
return this.repository.listByEntityId(entityId);
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* List metadata history for an entity, ordered by validFrom desc.
|
|
572
|
+
*/
|
|
573
|
+
listHistory(entityId) {
|
|
574
|
+
return this.repository.listHistoryByEntityId(entityId);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Bulk upsert metadata values.
|
|
578
|
+
*/
|
|
579
|
+
upsertValues(inputs, conflictTarget) {
|
|
580
|
+
return this.repository.upsertMany(inputs, conflictTarget);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// runtime/base-classes/knowledge-entity-service.ts
|
|
585
|
+
var KnowledgeEntityService = class extends BaseService {
|
|
586
|
+
// pgvector-dependent methods will be added when the extension is available:
|
|
587
|
+
// semanticSearch, findPendingByOpportunityId, updateStatus, updateStatusBatch
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
// runtime/base-classes/with-analytics.ts
|
|
591
|
+
function WithAnalytics(Base) {
|
|
592
|
+
class WithAnalyticsMixin extends Base {
|
|
593
|
+
analytics;
|
|
594
|
+
}
|
|
595
|
+
return WithAnalyticsMixin;
|
|
596
|
+
}
|
|
597
|
+
export {
|
|
598
|
+
ActivityEntityRepository,
|
|
599
|
+
ActivityEntityService,
|
|
600
|
+
BaseFindByIdUseCase,
|
|
601
|
+
BaseListUseCase,
|
|
602
|
+
BaseRepository,
|
|
603
|
+
BaseService,
|
|
604
|
+
KnowledgeEntityRepository,
|
|
605
|
+
KnowledgeEntityService,
|
|
606
|
+
MetadataEntityRepository,
|
|
607
|
+
MetadataEntityService,
|
|
608
|
+
SyncedEntityRepository,
|
|
609
|
+
SyncedEntityService,
|
|
610
|
+
WithAnalytics,
|
|
611
|
+
buildChangeEvents,
|
|
612
|
+
buildLifecycleEvent,
|
|
613
|
+
diffSnapshots,
|
|
614
|
+
emitSafely,
|
|
615
|
+
entitySnapshot
|
|
616
|
+
};
|
|
617
|
+
//# sourceMappingURL=index.js.map
|