@pattern-stack/codegen 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/consumer-skills/entities/families-and-queries.md +5 -3
  3. package/dist/{chunk-DGYTSCKN.js → chunk-3MAZ4TQH.js} +13 -13
  4. package/dist/{chunk-5LXOJGO2.js → chunk-3VEVGL74.js} +5 -5
  5. package/dist/{chunk-Y7GDG744.js → chunk-4GLNY5V6.js} +5 -5
  6. package/dist/{chunk-RUSUZZAF.js → chunk-4MVGAMUA.js} +4 -4
  7. package/dist/{chunk-T6SCOJF4.js → chunk-7LKAMLV4.js} +4 -4
  8. package/dist/{chunk-T4YJRD22.js → chunk-BULPAAD3.js} +4 -4
  9. package/dist/{chunk-QSJ3J4HE.js → chunk-CDLWYZVQ.js} +4 -4
  10. package/dist/{chunk-XWBK3XJK.js → chunk-DCCZB4UC.js} +4 -4
  11. package/dist/{chunk-DLG62MQY.js → chunk-DTXH24LR.js} +6 -6
  12. package/dist/{chunk-AYC2HEAL.js → chunk-GJDEPTPY.js} +7 -7
  13. package/dist/{chunk-2WDX6I7T.js → chunk-IOQMMH6C.js} +16 -6
  14. package/dist/{chunk-2WDX6I7T.js.map → chunk-IOQMMH6C.js.map} +1 -1
  15. package/dist/{chunk-BOPZWRJK.js → chunk-JYBFPNBJ.js} +8 -8
  16. package/dist/chunk-JYBFPNBJ.js.map +1 -0
  17. package/dist/{chunk-CRBVI4GE.js → chunk-L3VJ47BU.js} +3 -3
  18. package/dist/chunk-MKWQKKK7.js +72 -0
  19. package/dist/chunk-MKWQKKK7.js.map +1 -0
  20. package/dist/{chunk-TDEHU73T.js → chunk-OGIZXGPY.js} +4 -4
  21. package/dist/{chunk-JM3T27ZW.js → chunk-OITTYGJS.js} +4 -4
  22. package/dist/{chunk-IT6FRTEW.js → chunk-OTR44OH6.js} +10 -10
  23. package/dist/{chunk-24WXSC3C.js → chunk-P3AYBRP6.js} +7 -7
  24. package/dist/{chunk-TKVTEUBD.js → chunk-RHYNACZS.js} +3 -3
  25. package/dist/{chunk-YK5JEVLX.js → chunk-SR7F3TJY.js} +4 -4
  26. package/dist/{chunk-H6FO2ZDJ.js → chunk-UTNWFHJF.js} +7 -7
  27. package/dist/{chunk-LQ6PYFU6.js → chunk-Z7PQCAVK.js} +4 -4
  28. package/dist/runtime/base-classes/activity-entity-repository.d.ts +39 -7
  29. package/dist/runtime/base-classes/activity-entity-repository.js +1 -1
  30. package/dist/runtime/base-classes/activity-entity-service.d.ts +12 -10
  31. package/dist/runtime/base-classes/activity-entity-service.js +1 -1
  32. package/dist/runtime/base-classes/index.js +23 -23
  33. package/dist/runtime/shared/openapi/index.js +5 -5
  34. package/dist/runtime/shared/openapi/registry.js +2 -2
  35. package/dist/runtime/subsystems/auth/auth.module.js +2 -2
  36. package/dist/runtime/subsystems/auth/index.js +8 -8
  37. package/dist/runtime/subsystems/bridge/bridge-outbox-drain-hook.js +3 -3
  38. package/dist/runtime/subsystems/bridge/bridge.module.js +14 -14
  39. package/dist/runtime/subsystems/bridge/index.js +14 -14
  40. package/dist/runtime/subsystems/cache/cache.module.js +1 -1
  41. package/dist/runtime/subsystems/cache/index.js +3 -3
  42. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +3 -3
  43. package/dist/runtime/subsystems/events/event-bus.memory-backend.js +2 -2
  44. package/dist/runtime/subsystems/events/events.module.js +5 -5
  45. package/dist/runtime/subsystems/events/index.js +5 -5
  46. package/dist/runtime/subsystems/index.js +101 -101
  47. package/dist/runtime/subsystems/integration/execute-integration.use-case.js +2 -2
  48. package/dist/runtime/subsystems/integration/index.js +41 -41
  49. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js +2 -2
  50. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js +2 -2
  51. package/dist/runtime/subsystems/integration/integration.module.js +5 -5
  52. package/dist/runtime/subsystems/jobs/index.js +35 -35
  53. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js +5 -5
  54. package/dist/runtime/subsystems/jobs/job-orchestrator.drizzle-backend.js +3 -3
  55. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js +2 -2
  56. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js +3 -3
  57. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +2 -2
  58. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js +3 -3
  59. package/dist/runtime/subsystems/jobs/job-worker.js +2 -2
  60. package/dist/runtime/subsystems/jobs/job-worker.module.js +11 -11
  61. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +9 -9
  62. package/dist/runtime/subsystems/storage/index.js +5 -5
  63. package/dist/runtime/subsystems/storage/storage.module.js +3 -3
  64. package/dist/src/cli/index.js +14 -14
  65. package/dist/src/index.d.ts +23 -8
  66. package/dist/src/index.js +12 -12
  67. package/package.json +2 -1
  68. package/runtime/base-classes/activity-entity-repository.ts +72 -13
  69. package/runtime/base-classes/activity-entity-service.ts +14 -12
  70. package/src/patterns/library/activity.pattern.ts +40 -10
  71. package/dist/chunk-BOPZWRJK.js.map +0 -1
  72. package/dist/chunk-XCEI7NUH.js +0 -41
  73. package/dist/chunk-XCEI7NUH.js.map +0 -1
  74. /package/dist/{chunk-DGYTSCKN.js.map → chunk-3MAZ4TQH.js.map} +0 -0
  75. /package/dist/{chunk-5LXOJGO2.js.map → chunk-3VEVGL74.js.map} +0 -0
  76. /package/dist/{chunk-Y7GDG744.js.map → chunk-4GLNY5V6.js.map} +0 -0
  77. /package/dist/{chunk-RUSUZZAF.js.map → chunk-4MVGAMUA.js.map} +0 -0
  78. /package/dist/{chunk-T6SCOJF4.js.map → chunk-7LKAMLV4.js.map} +0 -0
  79. /package/dist/{chunk-T4YJRD22.js.map → chunk-BULPAAD3.js.map} +0 -0
  80. /package/dist/{chunk-QSJ3J4HE.js.map → chunk-CDLWYZVQ.js.map} +0 -0
  81. /package/dist/{chunk-XWBK3XJK.js.map → chunk-DCCZB4UC.js.map} +0 -0
  82. /package/dist/{chunk-DLG62MQY.js.map → chunk-DTXH24LR.js.map} +0 -0
  83. /package/dist/{chunk-AYC2HEAL.js.map → chunk-GJDEPTPY.js.map} +0 -0
  84. /package/dist/{chunk-CRBVI4GE.js.map → chunk-L3VJ47BU.js.map} +0 -0
  85. /package/dist/{chunk-TDEHU73T.js.map → chunk-OGIZXGPY.js.map} +0 -0
  86. /package/dist/{chunk-JM3T27ZW.js.map → chunk-OITTYGJS.js.map} +0 -0
  87. /package/dist/{chunk-IT6FRTEW.js.map → chunk-OTR44OH6.js.map} +0 -0
  88. /package/dist/{chunk-24WXSC3C.js.map → chunk-P3AYBRP6.js.map} +0 -0
  89. /package/dist/{chunk-TKVTEUBD.js.map → chunk-RHYNACZS.js.map} +0 -0
  90. /package/dist/{chunk-YK5JEVLX.js.map → chunk-SR7F3TJY.js.map} +0 -0
  91. /package/dist/{chunk-H6FO2ZDJ.js.map → chunk-UTNWFHJF.js.map} +0 -0
  92. /package/dist/{chunk-LQ6PYFU6.js.map → chunk-Z7PQCAVK.js.map} +0 -0
@@ -1,26 +1,84 @@
1
1
  /**
2
2
  * ActivityEntityRepository<TEntity>
3
3
  *
4
- * Family-specific base for activity entities (emails, calls, meetings, notes).
5
- * Adds date-range queries, user/opportunity scoping, and recency ordering.
4
+ * Family-specific base for activity / interaction entities (emails, calls,
5
+ * meetings, messages, transcripts). Adds date-range queries, actor (`user_id`)
6
+ * scoping, recency ordering, and **config-driven subject scoping** — the
7
+ * subject FK column is resolved from the concrete repo's `patternConfig`
8
+ * (ADR-031 §4) rather than hardcoded, so the same base serves a CRM
9
+ * `opportunity`-scoped activity and a swe-brain `person`-scoped interaction.
6
10
  *
7
- * Concrete repos extend this and declare their table + behaviors.
11
+ * Concrete repos extend this and declare their table + behaviors, and (when
12
+ * they use the subject finders) a `patternConfig` carrying `subject` /
13
+ * `subjectColumn` / `occurredAt`. The template emits that property from the
14
+ * entity's `config: { Activity: {...} }` block. See ACTIVITY-SUBJECT-1.
8
15
  */
9
16
  import { eq, between, desc } from 'drizzle-orm';
10
17
  import { BaseRepository } from './base-repository';
11
18
 
19
+ /**
20
+ * Per-entity Activity config (matches `ActivityPatternConfigSchema` in
21
+ * `src/patterns/library/activity.pattern.ts`). Carried on the concrete repo as
22
+ * `patternConfig` and read here to resolve column names at runtime.
23
+ */
24
+ export interface ActivityPatternConfig {
25
+ /** Subject entity name → derives the FK column `<subject>_id`. */
26
+ subject?: string;
27
+ /** Explicit snake_case FK column, when it does not follow `<subject>_id`. */
28
+ subjectColumn?: string;
29
+ /** snake_case recency-ordering column; defaults to `occurred_at`. */
30
+ occurredAt?: string;
31
+ }
32
+
33
+ const toCamel = (snake: string): string =>
34
+ snake.replace(/_([a-z0-9])/g, (_, c: string) => c.toUpperCase());
35
+
12
36
  export abstract class ActivityEntityRepository<TEntity> extends BaseRepository<TEntity> {
13
37
  /**
14
- * Find activities within a date range (inclusive).
38
+ * Per-entity Activity config. The template emits this from `config:
39
+ * { Activity: {...} }`; entities that only use date-range / user scoping omit
40
+ * it (and must not call the subject finders).
41
+ */
42
+ protected readonly patternConfig?: ActivityPatternConfig;
43
+
44
+ /**
45
+ * camelCase key for the recency-ordering column. Defaults to `occurredAt`
46
+ * (column `occurred_at`); override via `patternConfig.occurredAt`.
47
+ */
48
+ protected get occurredAtColumn(): string {
49
+ const snake = this.patternConfig?.occurredAt ?? 'occurred_at';
50
+ return toCamel(snake);
51
+ }
52
+
53
+ /**
54
+ * camelCase key for the subject FK column, resolved from `patternConfig`:
55
+ * `subjectColumn` (explicit) → `<subject>_id` (derived). Throws when neither
56
+ * is configured — the subject finders are unusable without it, and a clear
57
+ * error beats a silent `undefined` column index.
58
+ */
59
+ protected get subjectColumn(): string {
60
+ const explicit = this.patternConfig?.subjectColumn;
61
+ if (explicit) return toCamel(explicit);
62
+ const subject = this.patternConfig?.subject;
63
+ if (subject) return toCamel(`${subject}_id`);
64
+ throw new Error(
65
+ 'ActivityEntityRepository: subject finders require a subject column. ' +
66
+ "Set `config: { Activity: { subject: '<entity>' } }` (→ <entity>_id) " +
67
+ "or `config: { Activity: { subjectColumn: '<column>' } }` on the entity YAML.",
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Find activities within a date range (inclusive), by the recency column.
15
73
  */
16
74
  async findByDateRange(start: Date, end: Date): Promise<TEntity[]> {
17
75
  const rows = await this.baseQuery()
18
- .where(between(this.table['occurredAt'], start, end));
76
+ .where(between(this.table[this.occurredAtColumn], start, end));
19
77
  return rows as TEntity[];
20
78
  }
21
79
 
22
80
  /**
23
- * Find all activities for a specific user.
81
+ * Find all activities for a specific user (actor / owner scoping).
24
82
  */
25
83
  async findByUserId(userId: string): Promise<TEntity[]> {
26
84
  const rows = await this.baseQuery()
@@ -29,21 +87,22 @@ export abstract class ActivityEntityRepository<TEntity> extends BaseRepository<T
29
87
  }
30
88
 
31
89
  /**
32
- * Find all activities for a specific opportunity.
90
+ * Find all activities for a specific subject (config-driven FK column).
33
91
  */
34
- async findByOpportunityId(opportunityId: string): Promise<TEntity[]> {
92
+ async findBySubjectId(subjectId: string): Promise<TEntity[]> {
35
93
  const rows = await this.baseQuery()
36
- .where(eq(this.table['opportunityId'], opportunityId));
94
+ .where(eq(this.table[this.subjectColumn], subjectId));
37
95
  return rows as TEntity[];
38
96
  }
39
97
 
40
98
  /**
41
- * Find the most recent activities for an opportunity, ordered by occurredAt desc.
99
+ * Find the most recent activities for a subject, ordered by the recency
100
+ * column descending.
42
101
  */
43
- async findRecentByOpportunityId(opportunityId: string, limit = 10): Promise<TEntity[]> {
102
+ async findRecentBySubjectId(subjectId: string, limit = 10): Promise<TEntity[]> {
44
103
  const rows = await this.baseQuery()
45
- .where(eq(this.table['opportunityId'], opportunityId))
46
- .orderBy(desc(this.table['occurredAt']))
104
+ .where(eq(this.table[this.subjectColumn], subjectId))
105
+ .orderBy(desc(this.table[this.occurredAtColumn]))
47
106
  .limit(limit);
48
107
  return rows as TEntity[];
49
108
  }
@@ -1,17 +1,19 @@
1
1
  /**
2
2
  * ActivityEntityService<TRepo, TEntity>
3
3
  *
4
- * Family-specific base service for activity entities.
5
- * Delegates to an activity repository that provides date-range,
6
- * user, and opportunity queries.
4
+ * Family-specific base service for activity / interaction entities. Delegates
5
+ * to an activity repository that provides date-range, actor (`user_id`), and
6
+ * config-driven subject queries. The subject FK column is resolved inside the
7
+ * repository from its `patternConfig` (ADR-031 §4) — the service is
8
+ * subject-name-agnostic. See ACTIVITY-SUBJECT-1.
7
9
  */
8
10
  import { BaseService, type IBaseRepository } from './base-service';
9
11
 
10
12
  export interface IActivityEntityRepository<TEntity> extends IBaseRepository<TEntity> {
11
13
  findByDateRange(start: Date, end: Date): Promise<TEntity[]>;
12
14
  findByUserId(userId: string): Promise<TEntity[]>;
13
- findByOpportunityId(opportunityId: string): Promise<TEntity[]>;
14
- findRecentByOpportunityId(opportunityId: string, limit?: number): Promise<TEntity[]>;
15
+ findBySubjectId(subjectId: string): Promise<TEntity[]>;
16
+ findRecentBySubjectId(subjectId: string, limit?: number): Promise<TEntity[]>;
15
17
  }
16
18
 
17
19
  export abstract class ActivityEntityService<
@@ -26,23 +28,23 @@ export abstract class ActivityEntityService<
26
28
  }
27
29
 
28
30
  /**
29
- * Find all activities for a specific user.
31
+ * Find all activities for a specific user (actor / owner scoping).
30
32
  */
31
33
  findByUser(userId: string): Promise<TEntity[]> {
32
34
  return this.repository.findByUserId(userId);
33
35
  }
34
36
 
35
37
  /**
36
- * Find all activities for a specific opportunity.
38
+ * Find all activities for a specific subject (config-driven FK column).
37
39
  */
38
- findByOpportunity(opportunityId: string): Promise<TEntity[]> {
39
- return this.repository.findByOpportunityId(opportunityId);
40
+ findBySubject(subjectId: string): Promise<TEntity[]> {
41
+ return this.repository.findBySubjectId(subjectId);
40
42
  }
41
43
 
42
44
  /**
43
- * Find the most recent activities for an opportunity.
45
+ * Find the most recent activities for a subject.
44
46
  */
45
- findRecent(opportunityId: string, limit?: number): Promise<TEntity[]> {
46
- return this.repository.findRecentByOpportunityId(opportunityId, limit);
47
+ findRecent(subjectId: string, limit?: number): Promise<TEntity[]> {
48
+ return this.repository.findRecentBySubjectId(subjectId, limit);
47
49
  }
48
50
  }
@@ -1,17 +1,46 @@
1
1
  /**
2
- * ActivityPattern — replaces `family: activity`.
2
+ * ActivityPattern — config-driven subject-scoped interaction base.
3
3
  *
4
- * Activity entities represent time-bounded interactions (calls, meetings,
5
- * emails). The base repository/service expose date-range + opportunity +
6
- * user-scoped lookups on top of the standard CRUD methods.
4
+ * Activity entities represent interactions (calls, meetings, emails, messages,
5
+ * transcripts) that reference a *subject* the thing the interaction is about.
6
+ * Which subject is a per-entity fact, not a library constant: a CRM activity is
7
+ * scoped to an `opportunity`, a swe-brain interaction to a `person` (later
8
+ * `repo`/`team`, ADR-0006's Salesforce Activities-vs-Records shape). The base
9
+ * repository/service therefore expose **generic** subject-scoped finders
10
+ * (`findBySubjectId` / `findRecentBySubjectId`) that read the subject FK column
11
+ * from the entity's `config:` block, on top of the standard CRUD methods plus
12
+ * date-range and actor (`user_id`) scoping.
7
13
  *
8
- * Class names, import paths, and inherited-method strings match the
9
- * legacy `FAMILY_MAP` entry verbatim so PATTERN-5's template swap produces
10
- * byte-identical output.
14
+ * The subject FK column resolves from `config: { Activity: { ... } }`:
15
+ * - `subjectColumn` explicit snake_case column, OR
16
+ * - `<subject>_id` — derived from the `subject` entity name.
17
+ * The recency-ordering column is `occurredAt` (snake_case in config), default
18
+ * `occurred_at`. The base reads these via `this.patternConfig` — the same
19
+ * ADR-031 §4 hand-off `IntegratedEntityRepository` uses for `integrationConfig`.
20
+ *
21
+ * See `docs/specs/ACTIVITY-SUBJECT-1.md`.
11
22
  */
12
23
 
24
+ import { z } from 'zod';
13
25
  import { definePattern } from '../pattern-definition.js';
14
26
 
27
+ /**
28
+ * Per-entity `config: { Activity: {...} }` block, validated at parse time.
29
+ * All fields optional — a date/user-only Activity entity supplies no config
30
+ * (and the subject finders throw if called). `.strict()` rejects misspelled
31
+ * keys loudly, matching JunctionPattern.
32
+ */
33
+ const ActivityPatternConfigSchema = z
34
+ .object({
35
+ /** Subject entity name → derives the FK column `<subject>_id`. */
36
+ subject: z.string().optional(),
37
+ /** Explicit snake_case FK column, when it does not follow `<subject>_id`. */
38
+ subjectColumn: z.string().optional(),
39
+ /** snake_case recency-ordering column; defaults to `occurred_at`. */
40
+ occurredAt: z.string().optional(),
41
+ })
42
+ .strict();
43
+
15
44
  export const ActivityPattern = definePattern({
16
45
  name: 'Activity',
17
46
  extends: ['Base'],
@@ -19,14 +48,15 @@ export const ActivityPattern = definePattern({
19
48
  serviceClass: 'ActivityEntityService',
20
49
  repositoryImport: '@shared/base-classes/activity-entity-repository',
21
50
  serviceImport: '@shared/base-classes/activity-entity-service',
51
+ configSchema: ActivityPatternConfigSchema,
22
52
  repositoryInheritedMethods: [
23
53
  'findById, findByIds, list, count, exists, create, update, delete, upsertMany',
24
- 'findByDateRange, findByUserId, findByOpportunityId, findRecentByOpportunityId',
54
+ 'findByDateRange, findByUserId, findBySubjectId, findRecentBySubjectId',
25
55
  ],
26
56
  serviceInheritedMethods: [
27
57
  'findById, findByIds, list, count, exists, create, update, delete',
28
- 'findByDateRange, findByUserId, findByOpportunityId, findRecentByOpportunityId',
58
+ 'findByDateRange, findByUser, findBySubject, findRecent',
29
59
  ],
30
60
  description:
31
- 'Time-bounded interaction entities — date-range + opportunity scoped lookups',
61
+ 'Subject-scoped interaction entities — date-range + actor + config-driven subject lookups',
32
62
  });
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../runtime/base-classes/activity-entity-service.ts"],"sourcesContent":["/**\n * ActivityEntityService<TRepo, TEntity>\n *\n * Family-specific base service for activity entities.\n * Delegates to an activity repository that provides date-range,\n * user, and opportunity queries.\n */\nimport { BaseService, type IBaseRepository } from './base-service';\n\nexport interface IActivityEntityRepository<TEntity> extends IBaseRepository<TEntity> {\n findByDateRange(start: Date, end: Date): Promise<TEntity[]>;\n findByUserId(userId: string): Promise<TEntity[]>;\n findByOpportunityId(opportunityId: string): Promise<TEntity[]>;\n findRecentByOpportunityId(opportunityId: string, limit?: number): Promise<TEntity[]>;\n}\n\nexport abstract class ActivityEntityService<\n TRepo extends IActivityEntityRepository<TEntity>,\n TEntity,\n> extends BaseService<TRepo, TEntity> {\n /**\n * Find activities within a date range (inclusive).\n */\n findByDateRange(start: Date, end: Date): Promise<TEntity[]> {\n return this.repository.findByDateRange(start, end);\n }\n\n /**\n * Find all activities for a specific user.\n */\n findByUser(userId: string): Promise<TEntity[]> {\n return this.repository.findByUserId(userId);\n }\n\n /**\n * Find all activities for a specific opportunity.\n */\n findByOpportunity(opportunityId: string): Promise<TEntity[]> {\n return this.repository.findByOpportunityId(opportunityId);\n }\n\n /**\n * Find the most recent activities for an opportunity.\n */\n findRecent(opportunityId: string, limit?: number): Promise<TEntity[]> {\n return this.repository.findRecentByOpportunityId(opportunityId, limit);\n }\n}\n"],"mappings":";;;;;AAgBO,IAAe,wBAAf,cAGG,YAA4B;AAAA;AAAA;AAAA;AAAA,EAIpC,gBAAgB,OAAa,KAA+B;AAC1D,WAAO,KAAK,WAAW,gBAAgB,OAAO,GAAG;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW,QAAoC;AAC7C,WAAO,KAAK,WAAW,aAAa,MAAM;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAkB,eAA2C;AAC3D,WAAO,KAAK,WAAW,oBAAoB,aAAa;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW,eAAuB,OAAoC;AACpE,WAAO,KAAK,WAAW,0BAA0B,eAAe,KAAK;AAAA,EACvE;AACF;","names":[]}
@@ -1,41 +0,0 @@
1
- import {
2
- BaseRepository
3
- } from "./chunk-J6KZS54B.js";
4
-
5
- // runtime/base-classes/activity-entity-repository.ts
6
- import { eq, between, desc } from "drizzle-orm";
7
- var ActivityEntityRepository = class extends BaseRepository {
8
- /**
9
- * Find activities within a date range (inclusive).
10
- */
11
- async findByDateRange(start, end) {
12
- const rows = await this.baseQuery().where(between(this.table["occurredAt"], start, end));
13
- return rows;
14
- }
15
- /**
16
- * Find all activities for a specific user.
17
- */
18
- async findByUserId(userId) {
19
- const rows = await this.baseQuery().where(eq(this.table["userId"], userId));
20
- return rows;
21
- }
22
- /**
23
- * Find all activities for a specific opportunity.
24
- */
25
- async findByOpportunityId(opportunityId) {
26
- const rows = await this.baseQuery().where(eq(this.table["opportunityId"], opportunityId));
27
- return rows;
28
- }
29
- /**
30
- * Find the most recent activities for an opportunity, ordered by occurredAt desc.
31
- */
32
- async findRecentByOpportunityId(opportunityId, limit = 10) {
33
- const rows = await this.baseQuery().where(eq(this.table["opportunityId"], opportunityId)).orderBy(desc(this.table["occurredAt"])).limit(limit);
34
- return rows;
35
- }
36
- };
37
-
38
- export {
39
- ActivityEntityRepository
40
- };
41
- //# sourceMappingURL=chunk-XCEI7NUH.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../runtime/base-classes/activity-entity-repository.ts"],"sourcesContent":["/**\n * ActivityEntityRepository<TEntity>\n *\n * Family-specific base for activity entities (emails, calls, meetings, notes).\n * Adds date-range queries, user/opportunity scoping, and recency ordering.\n *\n * Concrete repos extend this and declare their table + behaviors.\n */\nimport { eq, between, desc } from 'drizzle-orm';\nimport { BaseRepository } from './base-repository';\n\nexport abstract class ActivityEntityRepository<TEntity> extends BaseRepository<TEntity> {\n /**\n * Find activities within a date range (inclusive).\n */\n async findByDateRange(start: Date, end: Date): Promise<TEntity[]> {\n const rows = await this.baseQuery()\n .where(between(this.table['occurredAt'], start, end));\n return rows as TEntity[];\n }\n\n /**\n * Find all activities for a specific user.\n */\n async findByUserId(userId: string): Promise<TEntity[]> {\n const rows = await this.baseQuery()\n .where(eq(this.table['userId'], userId));\n return rows as TEntity[];\n }\n\n /**\n * Find all activities for a specific opportunity.\n */\n async findByOpportunityId(opportunityId: string): Promise<TEntity[]> {\n const rows = await this.baseQuery()\n .where(eq(this.table['opportunityId'], opportunityId));\n return rows as TEntity[];\n }\n\n /**\n * Find the most recent activities for an opportunity, ordered by occurredAt desc.\n */\n async findRecentByOpportunityId(opportunityId: string, limit = 10): Promise<TEntity[]> {\n const rows = await this.baseQuery()\n .where(eq(this.table['opportunityId'], opportunityId))\n .orderBy(desc(this.table['occurredAt']))\n .limit(limit);\n return rows as TEntity[];\n }\n}\n"],"mappings":";;;;;AAQA,SAAS,IAAI,SAAS,YAAY;AAG3B,IAAe,2BAAf,cAAyD,eAAwB;AAAA;AAAA;AAAA;AAAA,EAItF,MAAM,gBAAgB,OAAa,KAA+B;AAChE,UAAM,OAAO,MAAM,KAAK,UAAU,EAC/B,MAAM,QAAQ,KAAK,MAAM,YAAY,GAAG,OAAO,GAAG,CAAC;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAAa,QAAoC;AACrD,UAAM,OAAO,MAAM,KAAK,UAAU,EAC/B,MAAM,GAAG,KAAK,MAAM,QAAQ,GAAG,MAAM,CAAC;AACzC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBAAoB,eAA2C;AACnE,UAAM,OAAO,MAAM,KAAK,UAAU,EAC/B,MAAM,GAAG,KAAK,MAAM,eAAe,GAAG,aAAa,CAAC;AACvD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,0BAA0B,eAAuB,QAAQ,IAAwB;AACrF,UAAM,OAAO,MAAM,KAAK,UAAU,EAC/B,MAAM,GAAG,KAAK,MAAM,eAAe,GAAG,aAAa,CAAC,EACpD,QAAQ,KAAK,KAAK,MAAM,YAAY,CAAC,CAAC,EACtC,MAAM,KAAK;AACd,WAAO;AAAA,EACT;AACF;","names":[]}