@pattern-stack/codegen 0.22.0 → 0.24.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 (104) hide show
  1. package/CHANGELOG.md +56 -1
  2. package/consumer-skills/integration/SKILL.md +11 -3
  3. package/dist/{chunk-XKWOJZZ4.js → chunk-37PILMIT.js} +4 -4
  4. package/dist/{chunk-NR7QQ6ZI.js → chunk-6M6LZEP6.js} +3 -3
  5. package/dist/{chunk-VDL5CJ5C.js → chunk-7B7MMDOJ.js} +54 -1
  6. package/dist/chunk-7B7MMDOJ.js.map +1 -0
  7. package/dist/{chunk-NXHL5YII.js → chunk-7LKAMLV4.js} +4 -4
  8. package/dist/{chunk-6DQEIXYU.js → chunk-CKLM57IE.js} +10 -10
  9. package/dist/chunk-CKLM57IE.js.map +1 -0
  10. package/dist/{chunk-QXVCRA23.js → chunk-ENAR3F5S.js} +9 -4
  11. package/dist/chunk-ENAR3F5S.js.map +1 -0
  12. package/dist/{chunk-FFUDEIFF.js → chunk-HN5HT5WL.js} +2 -2
  13. package/dist/{chunk-6ECCJVYW.js → chunk-K4BQQ2NN.js} +46 -2
  14. package/dist/chunk-K4BQQ2NN.js.map +1 -0
  15. package/dist/{chunk-QFUIE37H.js → chunk-KFXXOFDC.js} +4 -4
  16. package/dist/{chunk-O2A6XHGD.js → chunk-LLDJS7PJ.js} +2 -2
  17. package/dist/{chunk-JOBQ6RUU.js → chunk-LQZESSM3.js} +28 -1
  18. package/dist/chunk-LQZESSM3.js.map +1 -0
  19. package/dist/{chunk-JRQO2IOF.js → chunk-MU54DZCC.js} +27 -1
  20. package/dist/chunk-MU54DZCC.js.map +1 -0
  21. package/dist/{chunk-INO47JXD.js → chunk-PBENHIN2.js} +3 -3
  22. package/dist/{chunk-CLWBNXKF.js → chunk-PLUJEQLU.js} +2 -2
  23. package/dist/{chunk-DB5UXJC3.js → chunk-PNCOUFFI.js} +4 -2
  24. package/dist/chunk-PNCOUFFI.js.map +1 -0
  25. package/dist/{chunk-S7C6TIIF.js → chunk-S5G3HO7N.js} +3 -1
  26. package/dist/chunk-S5G3HO7N.js.map +1 -0
  27. package/dist/{chunk-FNHNSFIJ.js → chunk-WZOPWQN2.js} +2 -2
  28. package/dist/{chunk-TDEHU73T.js → chunk-YIVQ7KLS.js} +46 -5
  29. package/dist/chunk-YIVQ7KLS.js.map +1 -0
  30. package/dist/runtime/subsystems/auth/auth.module.js +2 -2
  31. package/dist/runtime/subsystems/auth/index.js +4 -4
  32. package/dist/runtime/subsystems/bridge/bridge.module.js +7 -7
  33. package/dist/runtime/subsystems/bridge/index.js +7 -7
  34. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +1 -1
  35. package/dist/runtime/subsystems/events/events.module.js +5 -5
  36. package/dist/runtime/subsystems/events/generated/bus.js +3 -3
  37. package/dist/runtime/subsystems/events/generated/index.d.ts +2 -2
  38. package/dist/runtime/subsystems/events/generated/index.js +9 -3
  39. package/dist/runtime/subsystems/events/generated/registry.d.ts +36 -0
  40. package/dist/runtime/subsystems/events/generated/registry.js +1 -1
  41. package/dist/runtime/subsystems/events/generated/schemas.d.ts +109 -1
  42. package/dist/runtime/subsystems/events/generated/schemas.js +7 -1
  43. package/dist/runtime/subsystems/events/generated/types.d.ts +48 -2
  44. package/dist/runtime/subsystems/events/index.js +5 -5
  45. package/dist/runtime/subsystems/index.d.ts +3 -2
  46. package/dist/runtime/subsystems/index.js +29 -25
  47. package/dist/runtime/subsystems/integration/execute-integration.use-case.d.ts +11 -1
  48. package/dist/runtime/subsystems/integration/execute-integration.use-case.js +2 -2
  49. package/dist/runtime/subsystems/integration/index.d.ts +2 -1
  50. package/dist/runtime/subsystems/integration/index.js +10 -8
  51. package/dist/runtime/subsystems/integration/integration-change-emitter.protocol.d.ts +106 -0
  52. package/dist/runtime/subsystems/integration/integration-change-emitter.protocol.js +1 -0
  53. package/dist/runtime/subsystems/integration/integration-change-emitter.protocol.js.map +1 -0
  54. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js +2 -2
  55. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js +2 -2
  56. package/dist/runtime/subsystems/integration/integration.module.js +4 -4
  57. package/dist/runtime/subsystems/integration/integration.tokens.d.ts +11 -1
  58. package/dist/runtime/subsystems/integration/integration.tokens.js +3 -1
  59. package/dist/runtime/subsystems/jobs/index.js +12 -12
  60. package/dist/runtime/subsystems/jobs/job-worker.d.ts +592 -4
  61. package/dist/runtime/subsystems/jobs/job-worker.js +3 -1
  62. package/dist/runtime/subsystems/jobs/job-worker.module.js +6 -6
  63. package/dist/runtime/subsystems/jobs/jobs-domain.module.d.ts +19 -0
  64. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +4 -4
  65. package/dist/runtime/subsystems/observability/index.js +3 -3
  66. package/dist/runtime/subsystems/observability/observability.module.js +3 -3
  67. package/dist/runtime/subsystems/observability/observability.service.js +2 -2
  68. package/dist/src/cli/index.js +413 -85
  69. package/dist/src/cli/index.js.map +1 -1
  70. package/dist/src/index.d.ts +490 -1
  71. package/dist/src/index.js +7 -7
  72. package/package.json +1 -1
  73. package/runtime/subsystems/events/event-bus.drizzle-backend.ts +23 -7
  74. package/runtime/subsystems/events/generated/registry.ts +27 -0
  75. package/runtime/subsystems/events/generated/schemas.ts +26 -0
  76. package/runtime/subsystems/events/generated/types.ts +52 -0
  77. package/runtime/subsystems/index.ts +23 -0
  78. package/runtime/subsystems/integration/execute-integration.use-case.ts +69 -1
  79. package/runtime/subsystems/integration/index.ts +6 -0
  80. package/runtime/subsystems/integration/integration-change-emitter.protocol.ts +107 -0
  81. package/runtime/subsystems/integration/integration.tokens.ts +11 -0
  82. package/runtime/subsystems/jobs/job-worker.module.ts +5 -0
  83. package/runtime/subsystems/jobs/job-worker.ts +126 -12
  84. package/runtime/subsystems/jobs/jobs-domain.module.ts +19 -0
  85. package/templates/entity/new/clean-lite-ps/prompt-extension.js +59 -10
  86. package/templates/subsystem/jobs-config/codegen-config-jobs-block.ejs.t +11 -0
  87. package/dist/chunk-6DQEIXYU.js.map +0 -1
  88. package/dist/chunk-6ECCJVYW.js.map +0 -1
  89. package/dist/chunk-DB5UXJC3.js.map +0 -1
  90. package/dist/chunk-JOBQ6RUU.js.map +0 -1
  91. package/dist/chunk-JRQO2IOF.js.map +0 -1
  92. package/dist/chunk-QXVCRA23.js.map +0 -1
  93. package/dist/chunk-S7C6TIIF.js.map +0 -1
  94. package/dist/chunk-TDEHU73T.js.map +0 -1
  95. package/dist/chunk-VDL5CJ5C.js.map +0 -1
  96. /package/dist/{chunk-XKWOJZZ4.js.map → chunk-37PILMIT.js.map} +0 -0
  97. /package/dist/{chunk-NR7QQ6ZI.js.map → chunk-6M6LZEP6.js.map} +0 -0
  98. /package/dist/{chunk-NXHL5YII.js.map → chunk-7LKAMLV4.js.map} +0 -0
  99. /package/dist/{chunk-FFUDEIFF.js.map → chunk-HN5HT5WL.js.map} +0 -0
  100. /package/dist/{chunk-QFUIE37H.js.map → chunk-KFXXOFDC.js.map} +0 -0
  101. /package/dist/{chunk-O2A6XHGD.js.map → chunk-LLDJS7PJ.js.map} +0 -0
  102. /package/dist/{chunk-INO47JXD.js.map → chunk-PBENHIN2.js.map} +0 -0
  103. /package/dist/{chunk-CLWBNXKF.js.map → chunk-PLUJEQLU.js.map} +0 -0
  104. /package/dist/{chunk-FNHNSFIJ.js.map → chunk-WZOPWQN2.js.map} +0 -0
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Integration subsystem — change-emitter protocol (port).
3
+ *
4
+ * `IIntegrationChangeEmitter` is the OPT-IN seam through which the generic
5
+ * orchestrator (`ExecuteIntegrationUseCase`) publishes a typed, data-level
6
+ * domain event after every sink write/soft-delete. It is the upstream-generalized
7
+ * form of the per-sink event emission swe-brain hand-built (ADR-0009 Amendment B):
8
+ * the differ already records `changed_fields` on `integration_run_items`, but
9
+ * nothing publishes a "this entity changed" domain event for downstream
10
+ * trigger→action consumers. This port closes that gap.
11
+ *
12
+ * ## Why a port (not a direct TypedEventBus call in the orchestrator)
13
+ *
14
+ * The orchestrator is strictly provider- AND entity-agnostic: `entityType` is a
15
+ * bare `string` and the canonical record is generic `T` (see the use-case header
16
+ * "No CRM bleed"). It therefore cannot know the typed event NAME
17
+ * (`<entity>_created`) or the typed payload shape at compile time. The typed
18
+ * knowledge lives at the per-entity assembly wiring (codegen knows the entity
19
+ * name there). So the orchestrator depends on this thin, untyped port; codegen
20
+ * binds a per-entity adapter that maps `(operation) → <entity>_<verb>` and calls
21
+ * the project's generated `TypedEventBus.publish(...)` with the typed payload.
22
+ *
23
+ * ## Backwards compatibility
24
+ *
25
+ * The port is `@Optional()` on the orchestrator. Entities that do NOT opt in
26
+ * (`integration.sink.emit_changes` absent/false) bind no emitter, so the
27
+ * orchestrator's `this.emitter` is `undefined` and NOTHING is published — zero
28
+ * behavior change. This is the invariant the snapshot fixture (which opts none
29
+ * in) keeps green.
30
+ *
31
+ * ## Provenance — loop-breaking
32
+ *
33
+ * Every emitted event carries `source: 'integration'` in its payload. A future
34
+ * write-back action (the Intervention layer in swe-brain terms) that subscribes
35
+ * to these events can detect `source === 'integration'` and decline to echo the
36
+ * change back to the vendor, breaking the inbound→writeback→inbound loop. This
37
+ * is the data-layer counterpart of the loopback middleware that already guards
38
+ * the read side (`createLoopbackMiddleware`).
39
+ *
40
+ * ## Transactionality
41
+ *
42
+ * `emitChange` receives the same `tx` the sink wrote under (when the sink exposes
43
+ * one — today the sink owns its own transaction internally, so `tx` is reserved
44
+ * for the future where the orchestrator drives the transaction). The generated
45
+ * adapter forwards `tx` into `TypedEventBus.publish(type, id, payload, { tx })`,
46
+ * so the event lands in the outbox iff the row commits (the events subsystem's
47
+ * outbox guarantee). When `tx` is absent the publish is post-commit best-effort,
48
+ * matching today's sink-owns-its-own-transaction reality.
49
+ */
50
+ /** The data-level action the orchestrator observed. Maps onto the generated
51
+ * event verb: `created → <entity>_created`, `updated → <entity>_edited`
52
+ * (per swe-brain ADR-0009 B1 — `_edited`, never `_updated`),
53
+ * `deleted → <entity>_deleted` (tombstone soft-delete). `noop` never emits. */
54
+ type IntegrationChangeAction = 'created' | 'updated' | 'deleted';
55
+ /**
56
+ * The vendor-blind change descriptor the orchestrator hands the emitter. The
57
+ * generated adapter reshapes this into the typed `<entity>_<verb>` payload
58
+ * (`{ entityId, externalId, provider, changedFields?, source: 'integration' }`).
59
+ */
60
+ interface IntegrationChangeNotification {
61
+ /** The local row id the sink wrote/soft-deleted (the domain aggregate id —
62
+ * becomes `aggregateId` on the published event AND `entityId` in the payload). */
63
+ readonly entityId: string;
64
+ /** Vendor-prefixed-or-bare external id the change keyed on (e.g. `slack:123`). */
65
+ readonly externalId: string;
66
+ /** Provider label from `ExecuteIntegrationInput.provider` (e.g. `'slack'`). */
67
+ readonly provider: string;
68
+ /** The observed action. `created`/`updated` come from the existing-row check;
69
+ * `deleted` from the soft-delete path. */
70
+ readonly action: IntegrationChangeAction;
71
+ /** The differ's structured per-field before/after map (the same value written
72
+ * to `integration_run_items.changed_fields`). Absent on deletes. */
73
+ readonly changedFields?: Record<string, unknown>;
74
+ /** Multi-tenant deployments thread the tenant id through to the event metadata. */
75
+ readonly tenantId?: string | null;
76
+ /** The transaction the sink wrote under, when the orchestrator drives one.
77
+ * Forwarded to `TypedEventBus.publish(..., { tx })` for the outbox guarantee.
78
+ * Reserved: today the sink owns its own transaction, so this is usually
79
+ * `undefined` and the publish is post-commit. Typed `unknown` here so the
80
+ * port stays free of a Drizzle type dependency (the generated adapter narrows). */
81
+ readonly tx?: unknown;
82
+ }
83
+ /**
84
+ * Post-upsert change-event emission port.
85
+ *
86
+ * One implementation per opted-in (entity, provider) assembly — codegen-emitted,
87
+ * bound to `INTEGRATION_CHANGE_EMITTER` in that assembly module. The orchestrator
88
+ * injects it `@Optional()`; an unbound token means no emission (back-compat).
89
+ */
90
+ interface IIntegrationChangeEmitter {
91
+ /**
92
+ * Publish the typed `<entity>_<verb>` domain event for one observed change.
93
+ *
94
+ * MUST be called only for real changes — the orchestrator never calls this on
95
+ * a `noop` diff (canonical state unchanged) or a delete that hit no local row
96
+ * (no tombstone created). Implementations should treat a call as "this thing
97
+ * happened" and publish unconditionally.
98
+ *
99
+ * Errors are the orchestrator's concern: it wraps the call so a failed publish
100
+ * does not abort the run (the row is already written; emission is best-effort
101
+ * unless ridden on the outbox tx). See `ExecuteIntegrationUseCase.processChange`.
102
+ */
103
+ emitChange(notification: IntegrationChangeNotification): Promise<void>;
104
+ }
105
+
106
+ export type { IIntegrationChangeEmitter, IntegrationChangeAction, IntegrationChangeNotification };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=integration-change-emitter.protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  PostgresCursorStore
3
- } from "../../../chunk-O2A6XHGD.js";
3
+ } from "../../../chunk-LLDJS7PJ.js";
4
4
  import "../../../chunk-HNWZFNKP.js";
5
- import "../../../chunk-S7C6TIIF.js";
5
+ import "../../../chunk-S5G3HO7N.js";
6
6
  import "../../../chunk-MZ6GV4YF.js";
7
7
  import "../../../chunk-U64T4YZE.js";
8
8
  import "../../../chunk-2E224ZSN.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  DrizzleIntegrationRunRecorder
3
- } from "../../../chunk-FFUDEIFF.js";
3
+ } from "../../../chunk-HN5HT5WL.js";
4
4
  import "../../../chunk-HNWZFNKP.js";
5
5
  import "../../../chunk-SQDOBLBP.js";
6
- import "../../../chunk-S7C6TIIF.js";
6
+ import "../../../chunk-S5G3HO7N.js";
7
7
  import "../../../chunk-MZ6GV4YF.js";
8
8
  import "../../../chunk-U64T4YZE.js";
9
9
  import "../../../chunk-2E224ZSN.js";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  IntegrationModule
3
- } from "../../../chunk-QFUIE37H.js";
4
- import "../../../chunk-FFUDEIFF.js";
3
+ } from "../../../chunk-KFXXOFDC.js";
4
+ import "../../../chunk-HN5HT5WL.js";
5
5
  import "../../../chunk-EO2QPOKH.js";
6
- import "../../../chunk-O2A6XHGD.js";
6
+ import "../../../chunk-LLDJS7PJ.js";
7
7
  import "../../../chunk-HNWZFNKP.js";
8
8
  import "../../../chunk-AHV4GDYM.js";
9
9
  import "../../../chunk-SQDOBLBP.js";
10
10
  import "../../../chunk-JEINYUJH.js";
11
- import "../../../chunk-S7C6TIIF.js";
11
+ import "../../../chunk-S5G3HO7N.js";
12
12
  import "../../../chunk-MZ6GV4YF.js";
13
13
  import "../../../chunk-U64T4YZE.js";
14
14
  import "../../../chunk-2E224ZSN.js";
@@ -23,6 +23,16 @@ declare const INTEGRATION_CHANGE_SOURCE: "INTEGRATION_CHANGE_SOURCE";
23
23
  declare const INTEGRATION_CURSOR_STORE: "INTEGRATION_CURSOR_STORE";
24
24
  declare const INTEGRATION_FIELD_DIFFER: "INTEGRATION_FIELD_DIFFER";
25
25
  declare const INTEGRATION_SINK: "INTEGRATION_SINK";
26
+ /**
27
+ * Optional post-upsert change-event emitter token (EMIT-CHANGES seam).
28
+ *
29
+ * Backed by `IIntegrationChangeEmitter`. Bound ONLY by codegen-emitted assembly
30
+ * modules whose entity opts in via `integration.sink.emit_changes: true`. The
31
+ * orchestrator injects it `@Optional()` — an unbound token means no domain
32
+ * events are published (the back-compat default for non-opted-in entities).
33
+ * See `integration-change-emitter.protocol.ts`.
34
+ */
35
+ declare const INTEGRATION_CHANGE_EMITTER: "INTEGRATION_CHANGE_EMITTER";
26
36
  /**
27
37
  * Run-recorder token (SYNC-5). Backed by `IIntegrationRunRecorder`. Drizzle impl
28
38
  * lands in SYNC-4; tests provide inline fakes.
@@ -57,4 +67,4 @@ declare const INTEGRATION_MULTI_TENANT: "INTEGRATION_MULTI_TENANT";
57
67
  */
58
68
  declare const ENTITY_CHANGE_SOURCE_REGISTRY: "ENTITY_CHANGE_SOURCE_REGISTRY";
59
69
 
60
- export { ENTITY_CHANGE_SOURCE_REGISTRY, INTEGRATION_CHANGE_SOURCE, INTEGRATION_CURSOR_STORE, INTEGRATION_FIELD_DIFFER, INTEGRATION_MODULE_OPTIONS, INTEGRATION_MULTI_TENANT, INTEGRATION_RUN_RECORDER, INTEGRATION_SINK };
70
+ export { ENTITY_CHANGE_SOURCE_REGISTRY, INTEGRATION_CHANGE_EMITTER, INTEGRATION_CHANGE_SOURCE, INTEGRATION_CURSOR_STORE, INTEGRATION_FIELD_DIFFER, INTEGRATION_MODULE_OPTIONS, INTEGRATION_MULTI_TENANT, INTEGRATION_RUN_RECORDER, INTEGRATION_SINK };
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ENTITY_CHANGE_SOURCE_REGISTRY,
3
+ INTEGRATION_CHANGE_EMITTER,
3
4
  INTEGRATION_CHANGE_SOURCE,
4
5
  INTEGRATION_CURSOR_STORE,
5
6
  INTEGRATION_FIELD_DIFFER,
@@ -7,10 +8,11 @@ import {
7
8
  INTEGRATION_MULTI_TENANT,
8
9
  INTEGRATION_RUN_RECORDER,
9
10
  INTEGRATION_SINK
10
- } from "../../../chunk-S7C6TIIF.js";
11
+ } from "../../../chunk-S5G3HO7N.js";
11
12
  import "../../../chunk-2E224ZSN.js";
12
13
  export {
13
14
  ENTITY_CHANGE_SOURCE_REGISTRY,
15
+ INTEGRATION_CHANGE_EMITTER,
14
16
  INTEGRATION_CHANGE_SOURCE,
15
17
  INTEGRATION_CURSOR_STORE,
16
18
  INTEGRATION_FIELD_DIFFER,
@@ -2,7 +2,7 @@ import "../../../chunk-W4HOHZVF.js";
2
2
  import {
3
3
  JobWorkerModule,
4
4
  JobWorkerOrchestrator
5
- } from "../../../chunk-QXVCRA23.js";
5
+ } from "../../../chunk-ENAR3F5S.js";
6
6
  import {
7
7
  JOB_WORKER_OPTIONS,
8
8
  JobWorker,
@@ -10,13 +10,10 @@ import {
10
10
  buildStaleSweepQuery,
11
11
  classifyError,
12
12
  computeBackoff
13
- } from "../../../chunk-VDL5CJ5C.js";
13
+ } from "../../../chunk-7B7MMDOJ.js";
14
14
  import {
15
15
  JobsDomainModule
16
- } from "../../../chunk-6DQEIXYU.js";
17
- import {
18
- MemoryJobOrchestrator
19
- } from "../../../chunk-VQOAATIG.js";
16
+ } from "../../../chunk-CKLM57IE.js";
20
17
  import {
21
18
  DrizzleJobRunService
22
19
  } from "../../../chunk-3VEVGL74.js";
@@ -27,12 +24,6 @@ import "../../../chunk-L3LZWWSX.js";
27
24
  import {
28
25
  DrizzleJobStepService
29
26
  } from "../../../chunk-DV4RV2DC.js";
30
- import {
31
- MemoryJobStepService
32
- } from "../../../chunk-PNZSGAB2.js";
33
- import {
34
- MemoryJobStore
35
- } from "../../../chunk-SNQ3TOWP.js";
36
27
  import {
37
28
  BULLMQ_CONNECTION,
38
29
  BULLMQ_RESOLVED_CONFIG,
@@ -49,6 +40,15 @@ import {
49
40
  import {
50
41
  DrizzleJobOrchestrator
51
42
  } from "../../../chunk-E6PLM6QG.js";
43
+ import {
44
+ MemoryJobOrchestrator
45
+ } from "../../../chunk-VQOAATIG.js";
46
+ import {
47
+ MemoryJobStepService
48
+ } from "../../../chunk-PNZSGAB2.js";
49
+ import {
50
+ MemoryJobStore
51
+ } from "../../../chunk-SNQ3TOWP.js";
52
52
  import {
53
53
  BootValidationError,
54
54
  JobCollisionError,