@pattern-stack/codegen 0.15.2 → 0.15.3
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 +32 -0
- package/dist/{chunk-COGHTKXY.js → chunk-27ETSJ2X.js} +2 -2
- package/dist/{chunk-WPXNN6QS.js → chunk-4H3PETLM.js} +6 -6
- package/dist/{chunk-24CWKBK5.js → chunk-4MF3HKJA.js} +3 -3
- package/dist/chunk-4MF3HKJA.js.map +1 -0
- package/dist/{chunk-T6C4LFLC.js → chunk-7YGORYZD.js} +4 -4
- package/dist/{chunk-I6MG4M3F.js → chunk-FBGHYQIZ.js} +4 -4
- package/dist/{chunk-WEVWJKOW.js → chunk-GCYKMF22.js} +7 -7
- package/dist/{chunk-OZZJDRGW.js → chunk-IYNSRIGR.js} +8 -8
- package/dist/{chunk-DKKFTHHI.js → chunk-J7JMVS2B.js} +4 -4
- package/dist/{chunk-KMZCQASO.js → chunk-O37C3YE6.js} +8 -8
- package/dist/{chunk-JRVNVKN6.js → chunk-RDVTWIYY.js} +7 -7
- package/dist/{chunk-7LKAMLV4.js → chunk-T6SCOJF4.js} +4 -4
- package/dist/{chunk-WRUUSZDJ.js → chunk-WWGYCIJX.js} +3 -3
- package/dist/{chunk-4OMHBMZJ.js → chunk-YLPAPPLW.js} +3 -3
- package/dist/chunk-YLPAPPLW.js.map +1 -0
- package/dist/runtime/base-classes/index.js +21 -21
- package/dist/runtime/subsystems/analytics/analytics.module.js +2 -2
- package/dist/runtime/subsystems/analytics/index.js +4 -4
- package/dist/runtime/subsystems/auth/auth.module.js +3 -3
- package/dist/runtime/subsystems/auth/index.js +6 -6
- package/dist/runtime/subsystems/bridge/bridge.module.js +11 -11
- package/dist/runtime/subsystems/bridge/index.js +17 -17
- package/dist/runtime/subsystems/cache/cache.drizzle-backend.js +2 -2
- package/dist/runtime/subsystems/cache/cache.module.js +3 -3
- package/dist/runtime/subsystems/cache/index.js +5 -5
- package/dist/runtime/subsystems/events/events.module.js +1 -1
- package/dist/runtime/subsystems/events/index.js +3 -3
- package/dist/runtime/subsystems/index.d.ts +5 -1
- package/dist/runtime/subsystems/index.js +70 -59
- package/dist/runtime/subsystems/integration/build-change-source.js +3 -3
- package/dist/runtime/subsystems/integration/index.js +24 -24
- package/dist/runtime/subsystems/integration/integration.module.js +3 -3
- package/dist/runtime/subsystems/integration/poll-change-source.d.ts +1 -1
- package/dist/runtime/subsystems/integration/poll-change-source.js +1 -1
- package/dist/runtime/subsystems/integration/webhook-change-source.d.ts +4 -3
- package/dist/runtime/subsystems/integration/webhook-change-source.js +1 -1
- package/dist/runtime/subsystems/jobs/index.js +18 -18
- package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js +4 -4
- package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js +2 -2
- package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +2 -2
- package/dist/runtime/subsystems/jobs/job-worker.module.js +7 -7
- package/dist/runtime/subsystems/jobs/jobs-domain.module.js +6 -6
- package/dist/runtime/subsystems/observability/index.js +3 -3
- package/dist/src/cli/index.js +10 -10
- package/dist/src/index.js +8 -8
- package/package.json +1 -1
- package/runtime/subsystems/index.ts +27 -0
- package/runtime/subsystems/integration/poll-change-source.ts +10 -7
- package/runtime/subsystems/integration/webhook-change-source.ts +12 -8
- package/dist/chunk-24CWKBK5.js.map +0 -1
- package/dist/chunk-4OMHBMZJ.js.map +0 -1
- /package/dist/{chunk-COGHTKXY.js.map → chunk-27ETSJ2X.js.map} +0 -0
- /package/dist/{chunk-WPXNN6QS.js.map → chunk-4H3PETLM.js.map} +0 -0
- /package/dist/{chunk-T6C4LFLC.js.map → chunk-7YGORYZD.js.map} +0 -0
- /package/dist/{chunk-I6MG4M3F.js.map → chunk-FBGHYQIZ.js.map} +0 -0
- /package/dist/{chunk-WEVWJKOW.js.map → chunk-GCYKMF22.js.map} +0 -0
- /package/dist/{chunk-OZZJDRGW.js.map → chunk-IYNSRIGR.js.map} +0 -0
- /package/dist/{chunk-DKKFTHHI.js.map → chunk-J7JMVS2B.js.map} +0 -0
- /package/dist/{chunk-KMZCQASO.js.map → chunk-O37C3YE6.js.map} +0 -0
- /package/dist/{chunk-JRVNVKN6.js.map → chunk-RDVTWIYY.js.map} +0 -0
- /package/dist/{chunk-7LKAMLV4.js.map → chunk-T6SCOJF4.js.map} +0 -0
- /package/dist/{chunk-WRUUSZDJ.js.map → chunk-WWGYCIJX.js.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MemoryJobRunService
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-RDVTWIYY.js";
|
|
4
|
+
import "../../../chunk-L3LZWWSX.js";
|
|
4
5
|
import "../../../chunk-SNQ3TOWP.js";
|
|
5
6
|
import "../../../chunk-T4BIIU5E.js";
|
|
6
|
-
import "../../../chunk-L3LZWWSX.js";
|
|
7
7
|
import "../../../chunk-BIO6F7YI.js";
|
|
8
8
|
import "../../../chunk-GYGNEQSC.js";
|
|
9
9
|
import "../../../chunk-2E224ZSN.js";
|
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
JOB_WORKER_MODULE_OPTIONS,
|
|
3
3
|
JobWorkerModule,
|
|
4
4
|
JobWorkerOrchestrator
|
|
5
|
-
} from "../../../chunk-
|
|
5
|
+
} from "../../../chunk-4H3PETLM.js";
|
|
6
6
|
import "../../../chunk-RC23QROE.js";
|
|
7
|
-
import "../../../chunk-
|
|
8
|
-
import "../../../chunk-
|
|
9
|
-
import "../../../chunk-
|
|
7
|
+
import "../../../chunk-O37C3YE6.js";
|
|
8
|
+
import "../../../chunk-FBGHYQIZ.js";
|
|
9
|
+
import "../../../chunk-RDVTWIYY.js";
|
|
10
|
+
import "../../../chunk-L3LZWWSX.js";
|
|
10
11
|
import "../../../chunk-DV4RV2DC.js";
|
|
12
|
+
import "../../../chunk-I6MVCB5A.js";
|
|
13
|
+
import "../../../chunk-RHVN6NA7.js";
|
|
11
14
|
import "../../../chunk-5Y7W3XR6.js";
|
|
12
15
|
import "../../../chunk-4RFHUZXU.js";
|
|
13
16
|
import "../../../chunk-PNZSGAB2.js";
|
|
14
17
|
import "../../../chunk-SNQ3TOWP.js";
|
|
15
18
|
import "../../../chunk-T4BIIU5E.js";
|
|
16
|
-
import "../../../chunk-L3LZWWSX.js";
|
|
17
|
-
import "../../../chunk-I6MVCB5A.js";
|
|
18
|
-
import "../../../chunk-RHVN6NA7.js";
|
|
19
19
|
import "../../../chunk-CO6LUM72.js";
|
|
20
20
|
import "../../../chunk-BIO6F7YI.js";
|
|
21
21
|
import "../../../chunk-OKXZ63IA.js";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JobsDomainModule
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-
|
|
5
|
-
import "../../../chunk-
|
|
3
|
+
} from "../../../chunk-O37C3YE6.js";
|
|
4
|
+
import "../../../chunk-FBGHYQIZ.js";
|
|
5
|
+
import "../../../chunk-RDVTWIYY.js";
|
|
6
|
+
import "../../../chunk-L3LZWWSX.js";
|
|
6
7
|
import "../../../chunk-DV4RV2DC.js";
|
|
8
|
+
import "../../../chunk-I6MVCB5A.js";
|
|
9
|
+
import "../../../chunk-RHVN6NA7.js";
|
|
7
10
|
import "../../../chunk-5Y7W3XR6.js";
|
|
8
11
|
import "../../../chunk-4RFHUZXU.js";
|
|
9
12
|
import "../../../chunk-PNZSGAB2.js";
|
|
10
13
|
import "../../../chunk-SNQ3TOWP.js";
|
|
11
14
|
import "../../../chunk-T4BIIU5E.js";
|
|
12
|
-
import "../../../chunk-L3LZWWSX.js";
|
|
13
|
-
import "../../../chunk-I6MVCB5A.js";
|
|
14
|
-
import "../../../chunk-RHVN6NA7.js";
|
|
15
15
|
import "../../../chunk-CO6LUM72.js";
|
|
16
16
|
import "../../../chunk-BIO6F7YI.js";
|
|
17
17
|
import "../../../chunk-OKXZ63IA.js";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import "../../../chunk-FI34KYZ5.js";
|
|
2
2
|
import "../../../chunk-L4SDDEEU.js";
|
|
3
|
+
import {
|
|
4
|
+
ObservabilityError
|
|
5
|
+
} from "../../../chunk-EWYCWP4H.js";
|
|
3
6
|
import {
|
|
4
7
|
ObservabilityModule
|
|
5
8
|
} from "../../../chunk-TNXH7BJS.js";
|
|
@@ -11,9 +14,6 @@ import {
|
|
|
11
14
|
OBSERVABILITY,
|
|
12
15
|
OBSERVABILITY_MODULE_OPTIONS
|
|
13
16
|
} from "../../../chunk-Y7RRSEOC.js";
|
|
14
|
-
import {
|
|
15
|
-
ObservabilityError
|
|
16
|
-
} from "../../../chunk-EWYCWP4H.js";
|
|
17
17
|
import "../../../chunk-BIO6F7YI.js";
|
|
18
18
|
import "../../../chunk-H5NH7KPE.js";
|
|
19
19
|
import "../../../chunk-4LH67P4U.js";
|
package/dist/src/cli/index.js
CHANGED
|
@@ -38,26 +38,26 @@ import {
|
|
|
38
38
|
writeManifest
|
|
39
39
|
} from "../../chunk-32DOFN3T.js";
|
|
40
40
|
import "../../chunk-KVOWSC5S.js";
|
|
41
|
-
import "../../chunk-
|
|
41
|
+
import "../../chunk-GCYKMF22.js";
|
|
42
|
+
import "../../chunk-EO2QPOKH.js";
|
|
42
43
|
import "../../chunk-PRWIX6UW.js";
|
|
44
|
+
import "../../chunk-DCCZB4UC.js";
|
|
43
45
|
import "../../chunk-AHV4GDYM.js";
|
|
44
46
|
import "../../chunk-SR7F3TJY.js";
|
|
45
|
-
import "../../chunk-EO2QPOKH.js";
|
|
46
47
|
import "../../chunk-SQDOBLBP.js";
|
|
48
|
+
import {
|
|
49
|
+
isDivisibleCursor
|
|
50
|
+
} from "../../chunk-3NMCDN7L.js";
|
|
47
51
|
import "../../chunk-4KNXX6TI.js";
|
|
48
52
|
import "../../chunk-3CJFPU6Q.js";
|
|
49
53
|
import "../../chunk-OGIZXGPY.js";
|
|
50
|
-
import "../../chunk-LG57S2SC.js";
|
|
51
|
-
import "../../chunk-DCCZB4UC.js";
|
|
52
54
|
import "../../chunk-MZ6GV4YF.js";
|
|
55
|
+
import "../../chunk-LG57S2SC.js";
|
|
53
56
|
import "../../chunk-HNWZFNKP.js";
|
|
54
|
-
import "../../chunk-
|
|
55
|
-
import "../../chunk-
|
|
56
|
-
import "../../chunk-
|
|
57
|
+
import "../../chunk-WWGYCIJX.js";
|
|
58
|
+
import "../../chunk-4MF3HKJA.js";
|
|
59
|
+
import "../../chunk-YLPAPPLW.js";
|
|
57
60
|
import "../../chunk-36U5UGIO.js";
|
|
58
|
-
import {
|
|
59
|
-
isDivisibleCursor
|
|
60
|
-
} from "../../chunk-3NMCDN7L.js";
|
|
61
61
|
import "../../chunk-S7C6TIIF.js";
|
|
62
62
|
import "../../chunk-U64T4YZE.js";
|
|
63
63
|
import "../../chunk-2E224ZSN.js";
|
package/dist/src/index.js
CHANGED
|
@@ -46,24 +46,24 @@ import {
|
|
|
46
46
|
validatePatternProject
|
|
47
47
|
} from "../chunk-32DOFN3T.js";
|
|
48
48
|
import "../chunk-KVOWSC5S.js";
|
|
49
|
-
import "../chunk-
|
|
49
|
+
import "../chunk-GCYKMF22.js";
|
|
50
|
+
import "../chunk-EO2QPOKH.js";
|
|
50
51
|
import "../chunk-PRWIX6UW.js";
|
|
52
|
+
import "../chunk-DCCZB4UC.js";
|
|
51
53
|
import "../chunk-AHV4GDYM.js";
|
|
52
54
|
import "../chunk-SR7F3TJY.js";
|
|
53
|
-
import "../chunk-EO2QPOKH.js";
|
|
54
55
|
import "../chunk-SQDOBLBP.js";
|
|
56
|
+
import "../chunk-3NMCDN7L.js";
|
|
55
57
|
import "../chunk-4KNXX6TI.js";
|
|
56
58
|
import "../chunk-3CJFPU6Q.js";
|
|
57
59
|
import "../chunk-OGIZXGPY.js";
|
|
58
|
-
import "../chunk-LG57S2SC.js";
|
|
59
|
-
import "../chunk-DCCZB4UC.js";
|
|
60
60
|
import "../chunk-MZ6GV4YF.js";
|
|
61
|
+
import "../chunk-LG57S2SC.js";
|
|
61
62
|
import "../chunk-HNWZFNKP.js";
|
|
62
|
-
import "../chunk-
|
|
63
|
-
import "../chunk-
|
|
64
|
-
import "../chunk-
|
|
63
|
+
import "../chunk-WWGYCIJX.js";
|
|
64
|
+
import "../chunk-4MF3HKJA.js";
|
|
65
|
+
import "../chunk-YLPAPPLW.js";
|
|
65
66
|
import "../chunk-36U5UGIO.js";
|
|
66
|
-
import "../chunk-3NMCDN7L.js";
|
|
67
67
|
import "../chunk-S7C6TIIF.js";
|
|
68
68
|
import "../chunk-U64T4YZE.js";
|
|
69
69
|
import "../chunk-2E224ZSN.js";
|
package/package.json
CHANGED
|
@@ -92,6 +92,33 @@ export type {
|
|
|
92
92
|
SourcedRecord,
|
|
93
93
|
} from './integration';
|
|
94
94
|
|
|
95
|
+
// Integration — change-source primitives + DetectionConfig (#226-3/4, ADR-033).
|
|
96
|
+
// Re-exported here so consumers authoring a webhook/poll drain across the
|
|
97
|
+
// package boundary import them from `@pattern-stack/codegen/subsystems` instead
|
|
98
|
+
// of reaching into the deep `.../integration/index` path. Surfaced by the
|
|
99
|
+
// swe-brain dogfood (gap #6 — the first real consumer of `WebhookChangeSource`,
|
|
100
|
+
// whose Slack inbound drain otherwise had to deep-import the primitive +
|
|
101
|
+
// `DetectionConfigSchema`). Selective re-export (mirrors the curated
|
|
102
|
+
// `IncrementalReadBase` / `ExecuteIntegrationUseCase` forwards above) — not
|
|
103
|
+
// `export *`, to keep the `IntegrationRunSummary` name clash contained.
|
|
104
|
+
export {
|
|
105
|
+
WebhookChangeSource,
|
|
106
|
+
PollChangeSource,
|
|
107
|
+
buildChangeSource,
|
|
108
|
+
DetectionConfigSchema,
|
|
109
|
+
} from './integration';
|
|
110
|
+
export type {
|
|
111
|
+
WebhookChangeSourceOptions,
|
|
112
|
+
WebhookFetchCallback,
|
|
113
|
+
WebhookFetchContext,
|
|
114
|
+
WebhookCursor,
|
|
115
|
+
PollChangeSourceOptions,
|
|
116
|
+
PollFetchCallback,
|
|
117
|
+
PollFetchContext,
|
|
118
|
+
PollCursor,
|
|
119
|
+
DetectionConfig,
|
|
120
|
+
} from './integration';
|
|
121
|
+
|
|
95
122
|
// Integration — assembly emission (RFC-0002). The generated per-entity sink
|
|
96
123
|
// imports `IIntegrationSink`; the generated per-entity assembly module imports
|
|
97
124
|
// `ExecuteIntegrationUseCase` + `INTEGRATION_CHANGE_SOURCE` + `INTEGRATION_SINK`
|
|
@@ -133,11 +133,14 @@ export class PollChangeSource<T> implements IChangeSource<T> {
|
|
|
133
133
|
}
|
|
134
134
|
const config = opts.config;
|
|
135
135
|
|
|
136
|
-
// Field mapping: locate the canonical `
|
|
137
|
-
// emit T already-mapped, but the primitive needs to know which key
|
|
138
|
-
// T carries the external id so it can stamp `Change.externalId`.
|
|
139
|
-
//
|
|
140
|
-
//
|
|
136
|
+
// Field mapping: locate the entry whose canonical `target` is `external_id`.
|
|
137
|
+
// Adapters emit T already-mapped, but the primitive needs to know which key
|
|
138
|
+
// on T carries the external id so it can stamp `Change.externalId`. That key
|
|
139
|
+
// is the mapping's `source` (the field on the emitted record), NOT its
|
|
140
|
+
// `target` (the canonical column) — they differ whenever the canonical
|
|
141
|
+
// record is vendor-neutral camelCase (e.g. `source: 'externalId'` →
|
|
142
|
+
// `target: 'external_id'`). Source of truth is the mapping table — codegen
|
|
143
|
+
// emits it from YAML, the primitive reads it here.
|
|
141
144
|
const externalIdMapping = config.mapping.find(
|
|
142
145
|
(m) => m.target === 'external_id',
|
|
143
146
|
);
|
|
@@ -146,7 +149,7 @@ export class PollChangeSource<T> implements IChangeSource<T> {
|
|
|
146
149
|
"PollChangeSource: DetectionConfig.mapping must include an entry with target 'external_id' so emitted Change<T>.externalId can be populated",
|
|
147
150
|
);
|
|
148
151
|
}
|
|
149
|
-
this.externalIdSourceField = externalIdMapping.
|
|
152
|
+
this.externalIdSourceField = externalIdMapping.source;
|
|
150
153
|
|
|
151
154
|
this.adapter = opts.adapter;
|
|
152
155
|
this.filters = config.filters;
|
|
@@ -196,7 +199,7 @@ export class PollChangeSource<T> implements IChangeSource<T> {
|
|
|
196
199
|
];
|
|
197
200
|
if (typeof externalIdRaw !== 'string' || externalIdRaw.length === 0) {
|
|
198
201
|
throw new Error(
|
|
199
|
-
`PollChangeSource: record missing string '${this.externalIdSourceField}' — emitted records MUST carry the canonical external id keyed by the mapping
|
|
202
|
+
`PollChangeSource: record missing string '${this.externalIdSourceField}' — emitted records MUST carry the canonical external id keyed by the mapping source`,
|
|
200
203
|
);
|
|
201
204
|
}
|
|
202
205
|
let dedupKey: string | undefined;
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* - canonical `Change<T>.source = 'webhook'` stamping;
|
|
10
10
|
* - `dedupKey` derivation from the configured `webhook.eventIdField` on
|
|
11
11
|
* the emitted record;
|
|
12
|
-
* - `externalId` derivation
|
|
13
|
-
*
|
|
12
|
+
* - `externalId` derivation: the mapping entry whose `target === 'external_id'`
|
|
13
|
+
* names — via its `source` — the field on the emitted record that carries
|
|
14
|
+
* the canonical external id (mirrors `PollChangeSource`);
|
|
14
15
|
* - middleware-chain composition via the locked `ChangeMiddleware<T>` shape
|
|
15
16
|
* (#226-1) — same composition seam as the poll primitive.
|
|
16
17
|
*
|
|
@@ -132,10 +133,13 @@ export class WebhookChangeSource<T> implements IChangeSource<T> {
|
|
|
132
133
|
}
|
|
133
134
|
const config = opts.config;
|
|
134
135
|
|
|
135
|
-
// Field mapping: locate the canonical `
|
|
136
|
-
// poll primitive's contract. Adapters emit records
|
|
137
|
-
// primitive needs to know which key on T carries the
|
|
138
|
-
// can stamp `Change.externalId`.
|
|
136
|
+
// Field mapping: locate the entry whose canonical `target` is `external_id`
|
|
137
|
+
// — mirrors the poll primitive's contract. Adapters emit records
|
|
138
|
+
// already-mapped; the primitive needs to know which key on T carries the
|
|
139
|
+
// external id so it can stamp `Change.externalId`. That key is the
|
|
140
|
+
// mapping's `source` (the field on the emitted record), NOT its `target`
|
|
141
|
+
// (the canonical column) — they differ whenever the canonical record is
|
|
142
|
+
// vendor-neutral camelCase (e.g. `source: 'externalId'` → `target: 'external_id'`).
|
|
139
143
|
const externalIdMapping = config.mapping.find(
|
|
140
144
|
(m) => m.target === 'external_id',
|
|
141
145
|
);
|
|
@@ -144,7 +148,7 @@ export class WebhookChangeSource<T> implements IChangeSource<T> {
|
|
|
144
148
|
"WebhookChangeSource: DetectionConfig.mapping must include an entry with target 'external_id' so emitted Change<T>.externalId can be populated",
|
|
145
149
|
);
|
|
146
150
|
}
|
|
147
|
-
this.externalIdSourceField = externalIdMapping.
|
|
151
|
+
this.externalIdSourceField = externalIdMapping.source;
|
|
148
152
|
this.eventIdSourceField = config.webhook.eventIdField;
|
|
149
153
|
|
|
150
154
|
this.queue = opts.queue;
|
|
@@ -183,7 +187,7 @@ export class WebhookChangeSource<T> implements IChangeSource<T> {
|
|
|
183
187
|
];
|
|
184
188
|
if (typeof externalIdRaw !== 'string' || externalIdRaw.length === 0) {
|
|
185
189
|
throw new Error(
|
|
186
|
-
`WebhookChangeSource: record missing string '${this.externalIdSourceField}' — emitted records MUST carry the canonical external id keyed by the mapping
|
|
190
|
+
`WebhookChangeSource: record missing string '${this.externalIdSourceField}' — emitted records MUST carry the canonical external id keyed by the mapping source`,
|
|
187
191
|
);
|
|
188
192
|
}
|
|
189
193
|
const eventIdRaw = (record as Record<string, unknown>)[
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../runtime/subsystems/integration/poll-change-source.ts"],"sourcesContent":["/**\n * Integration subsystem — `PollChangeSource<T>` primitive (#226-3, ADR-033).\n *\n * Generic poll-mode `IChangeSource<T>` implementation parameterized by a\n * parsed `DetectionConfig` (poll mode) and a consumer-supplied\n * `PollFetchCallback<T>`. The primitive owns:\n *\n * - filter resolution (flat-AND vocabulary per epic decision Q3 — richer\n * boolean expressions deferred);\n * - field mapping → `Change.externalId` derivation;\n * - cursor strategy passthrough (the orchestrator passes the prior cursor\n * by-value per ADR-033 / #226-2; the callback yields the next cursor\n * per record; the primitive simply stamps it onto `Change<T>`);\n * - `Change<T>.source` provenance (`'poll'` by default);\n * - middleware-chain composition (the `ChangeMiddleware<T>` shape\n * locked in #226-1).\n *\n * Shape locks (decision memo Q5):\n * - `PollFetchContext = { subscription, cursor, filters }` — explicitly\n * NO `userId` / `tenantId`. Run-scope identity is closed over by the\n * consumer at adapter construction (or resolved inside the callback\n * via consumer services). Threading it through the seam would force\n * port expansion every time run-context grows.\n *\n * The adapter callback returns `{ record: T; cursor: PollCursor }` — the\n * primitive does not reach into the record to extract a cursor itself.\n * `cursor.field` from `DetectionConfig.poll.cursor` is metadata for codegen\n * + adapters; the primitive trusts what the callback yielded.\n */\n\nimport type {\n DetectionConfig,\n ResolvedFilter,\n} from './detection-config.schema';\nimport type {\n Change,\n ChangeSource,\n IChangeSource,\n IntegrationSubscriptionView,\n} from './integration-change-source.protocol';\nimport type {\n ChangeIterator,\n ChangeMiddleware,\n} from './integration-middleware.protocol';\n\n// ============================================================================\n// Cursor + adapter callback shapes\n// ============================================================================\n\n/**\n * Opaque poll-cursor shape. Each provider/entity pair binds it concretely\n * via the cursor strategy (`{ systemModstamp }`, `{ replayId }`, etc.); the\n * primitive treats it as an opaque value to pass through.\n */\nexport type PollCursor = unknown;\n\n/**\n * The context the primitive forwards to the adapter callback. Locked to\n * exactly three fields per decision memo Q5 — `userId` / `tenantId` are\n * NOT here on purpose.\n */\nexport interface PollFetchContext {\n readonly subscription: IntegrationSubscriptionView;\n readonly cursor: PollCursor | null;\n readonly filters: readonly ResolvedFilter[];\n}\n\n/**\n * Consumer-supplied fetch callback. Returns an async iterable of\n * `{ record, cursor }` pairs — `record` is already the canonical `T`\n * (the adapter does provider-side translation), `cursor` is the post-record\n * cursor the orchestrator should persist if the run completes successfully.\n */\nexport type PollFetchCallback<T> = (\n ctx: PollFetchContext,\n) => AsyncIterable<{ record: T; cursor: PollCursor }>;\n\n// ============================================================================\n// Constructor options\n// ============================================================================\n\nexport interface PollChangeSourceOptions<T> {\n /** Consumer-supplied fetch callback. */\n readonly adapter: PollFetchCallback<T>;\n /**\n * Parsed detection config. MUST be `mode: 'poll'`; the constructor\n * throws if a webhook config is supplied. Codegen-emitted factories\n * call `DetectionConfigSchema.parse(...)` upstream so this is a safety\n * net, not the primary validation point.\n */\n readonly config: DetectionConfig;\n /**\n * Optional middleware chain. First element is the outermost layer:\n * sees `(subscription, cursor)` first and yielded `Change<T>` last.\n * Locked shape (#226-1) — the primitive composes them with its own\n * `listChanges` implementation as the innermost iterator.\n */\n readonly middlewares?: ReadonlyArray<ChangeMiddleware<T>>;\n /**\n * Optional human label for run logs (e.g. `'salesforce-poll-opportunity'`).\n * Defaults to a derived label based on the subscription domain at\n * construction time fallback — adapters are encouraged to provide one.\n */\n readonly label?: string;\n}\n\n// ============================================================================\n// PollChangeSource<T>\n// ============================================================================\n\nexport class PollChangeSource<T> implements IChangeSource<T> {\n public readonly label: string;\n\n private readonly adapter: PollFetchCallback<T>;\n private readonly filters: readonly ResolvedFilter[];\n private readonly externalIdSourceField: string;\n private readonly source: ChangeSource;\n /**\n * When `poll.provenance === 'cdc'`, the field on the emitted record from\n * which `Change<T>.dedupKey` is read — sourced from `poll.cursor.field`\n * (Stripe-style event endpoints carry the event id on the record itself\n * and the cursor advances over the same id). `null` for default poll\n * provenance, which does NOT populate `dedupKey`.\n */\n private readonly dedupKeySourceField: string | null;\n private readonly composed: ChangeIterator<T>;\n\n constructor(opts: PollChangeSourceOptions<T>) {\n if (opts.config.mode !== 'poll') {\n throw new Error(\n `PollChangeSource requires DetectionConfig.mode === 'poll'; got '${(opts.config as { mode: string }).mode}'`,\n );\n }\n const config = opts.config;\n\n // Field mapping: locate the canonical `external_id` target. Adapters\n // emit T already-mapped, but the primitive needs to know which key on\n // T carries the external id so it can stamp `Change.externalId`. Source\n // of truth is the mapping table — codegen emits it from YAML, the\n // primitive reads it here.\n const externalIdMapping = config.mapping.find(\n (m) => m.target === 'external_id',\n );\n if (!externalIdMapping) {\n throw new Error(\n \"PollChangeSource: DetectionConfig.mapping must include an entry with target 'external_id' so emitted Change<T>.externalId can be populated\",\n );\n }\n this.externalIdSourceField = externalIdMapping.target;\n\n this.adapter = opts.adapter;\n this.filters = config.filters;\n // Provenance: `mode: 'poll'` defaults to `'poll'`; opt into `'cdc'` via\n // `poll.provenance` (Stripe-style event endpoints — wired in #226-4).\n // CDC provenance also stamps `dedupKey` from the cursor's `field`, since\n // those endpoints surface a per-event id on each record (the same id the\n // cursor advances over).\n const isCdc = config.poll.provenance === 'cdc';\n this.source = isCdc ? 'cdc' : 'poll';\n this.dedupKeySourceField = isCdc ? config.poll.cursor.field : null;\n\n this.label =\n opts.label ?? `poll-change-source:${externalIdMapping.source}`;\n\n // Compose middleware chain. The terminal iterator is `this.fetch`\n // bound to `this`. First middleware in the array is the outermost\n // layer (sees subscription/cursor first, yielded changes last).\n const inner: ChangeIterator<T> = (sub, cur) => this.fetch(sub, cur);\n const middlewares = opts.middlewares ?? [];\n this.composed = middlewares.reduceRight<ChangeIterator<T>>(\n (next, mw) => mw(next),\n inner,\n );\n }\n\n listChanges(\n subscription: IntegrationSubscriptionView,\n cursor: unknown | null,\n ): AsyncIterable<Change<T>> {\n return this.composed(subscription, cursor);\n }\n\n private async *fetch(\n subscription: IntegrationSubscriptionView,\n cursor: unknown | null,\n ): AsyncIterable<Change<T>> {\n const ctx: PollFetchContext = {\n subscription,\n cursor: cursor as PollCursor | null,\n filters: this.filters,\n };\n\n for await (const { record, cursor: nextCursor } of this.adapter(ctx)) {\n const externalIdRaw = (record as Record<string, unknown>)[\n this.externalIdSourceField\n ];\n if (typeof externalIdRaw !== 'string' || externalIdRaw.length === 0) {\n throw new Error(\n `PollChangeSource: record missing string '${this.externalIdSourceField}' — emitted records MUST carry the canonical external id keyed by the mapping target`,\n );\n }\n let dedupKey: string | undefined;\n if (this.dedupKeySourceField !== null) {\n const dedupRaw = (record as Record<string, unknown>)[\n this.dedupKeySourceField\n ];\n if (typeof dedupRaw !== 'string' || dedupRaw.length === 0) {\n throw new Error(\n `PollChangeSource: cdc-provenance record missing string '${this.dedupKeySourceField}' — when poll.provenance === 'cdc' the cursor.field must be present on each record so dedupKey can be populated`,\n );\n }\n dedupKey = dedupRaw;\n }\n\n const change: Change<T> = {\n externalId: externalIdRaw,\n // Polling cannot distinguish create vs. update vs. delete on its\n // own — all yielded records are surfaced as 'updated'. The\n // orchestrator's diff stage classifies create-vs-update against\n // local state; soft-delete detection is out of scope for the\n // primitive (consumer drives via tombstone records or a separate\n // sweep — see ADR-033).\n operation: 'updated',\n record,\n cursor: nextCursor,\n source: this.source,\n ...(dedupKey !== undefined ? { dedupKey } : {}),\n };\n yield change;\n }\n }\n}\n"],"mappings":";AA8GO,IAAM,mBAAN,MAAsD;AAAA,EAC3C;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA;AAAA,EACA;AAAA,EAEjB,YAAY,MAAkC;AAC5C,QAAI,KAAK,OAAO,SAAS,QAAQ;AAC/B,YAAM,IAAI;AAAA,QACR,mEAAoE,KAAK,OAA4B,IAAI;AAAA,MAC3G;AAAA,IACF;AACA,UAAM,SAAS,KAAK;AAOpB,UAAM,oBAAoB,OAAO,QAAQ;AAAA,MACvC,CAAC,MAAM,EAAE,WAAW;AAAA,IACtB;AACA,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,SAAK,wBAAwB,kBAAkB;AAE/C,SAAK,UAAU,KAAK;AACpB,SAAK,UAAU,OAAO;AAMtB,UAAM,QAAQ,OAAO,KAAK,eAAe;AACzC,SAAK,SAAS,QAAQ,QAAQ;AAC9B,SAAK,sBAAsB,QAAQ,OAAO,KAAK,OAAO,QAAQ;AAE9D,SAAK,QACH,KAAK,SAAS,sBAAsB,kBAAkB,MAAM;AAK9D,UAAM,QAA2B,CAAC,KAAK,QAAQ,KAAK,MAAM,KAAK,GAAG;AAClE,UAAM,cAAc,KAAK,eAAe,CAAC;AACzC,SAAK,WAAW,YAAY;AAAA,MAC1B,CAAC,MAAM,OAAO,GAAG,IAAI;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YACE,cACA,QAC0B;AAC1B,WAAO,KAAK,SAAS,cAAc,MAAM;AAAA,EAC3C;AAAA,EAEA,OAAe,MACb,cACA,QAC0B;AAC1B,UAAM,MAAwB;AAAA,MAC5B;AAAA,MACA;AAAA,MACA,SAAS,KAAK;AAAA,IAChB;AAEA,qBAAiB,EAAE,QAAQ,QAAQ,WAAW,KAAK,KAAK,QAAQ,GAAG,GAAG;AACpE,YAAM,gBAAiB,OACrB,KAAK,qBACP;AACA,UAAI,OAAO,kBAAkB,YAAY,cAAc,WAAW,GAAG;AACnE,cAAM,IAAI;AAAA,UACR,4CAA4C,KAAK,qBAAqB;AAAA,QACxE;AAAA,MACF;AACA,UAAI;AACJ,UAAI,KAAK,wBAAwB,MAAM;AACrC,cAAM,WAAY,OAChB,KAAK,mBACP;AACA,YAAI,OAAO,aAAa,YAAY,SAAS,WAAW,GAAG;AACzD,gBAAM,IAAI;AAAA,YACR,2DAA2D,KAAK,mBAAmB;AAAA,UACrF;AAAA,QACF;AACA,mBAAW;AAAA,MACb;AAEA,YAAM,SAAoB;AAAA,QACxB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOZ,WAAW;AAAA,QACX;AAAA,QACA,QAAQ;AAAA,QACR,QAAQ,KAAK;AAAA,QACb,GAAI,aAAa,SAAY,EAAE,SAAS,IAAI,CAAC;AAAA,MAC/C;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../runtime/subsystems/integration/webhook-change-source.ts"],"sourcesContent":["/**\n * Integration subsystem — `WebhookChangeSource<T>` primitive (#226-4, ADR-033).\n *\n * Generic webhook-mode `IChangeSource<T>` implementation parameterized by a\n * parsed `DetectionConfig` (webhook mode) and a consumer-supplied\n * `WebhookFetchCallback<T>` that iterates a consumer-owned inbound staging\n * queue. The primitive owns:\n *\n * - canonical `Change<T>.source = 'webhook'` stamping;\n * - `dedupKey` derivation from the configured `webhook.eventIdField` on\n * the emitted record;\n * - `externalId` derivation from the mapping table's `external_id` target\n * (mirrors `PollChangeSource`);\n * - middleware-chain composition via the locked `ChangeMiddleware<T>` shape\n * (#226-1) — same composition seam as the poll primitive.\n *\n * The primitive is **passive**: it iterates whatever the consumer-owned\n * queue yields. It does NOT synchronously drive the orchestrator, does NOT\n * own a transport, and does NOT manage acks. The inbound staging table\n * schema is consumer-owned and deferred per ADR-0002 §Phase 4 — the\n * `WebhookFetchCallback<T>` is the queue contract the consumer injects.\n *\n * Shape locks (decision memo Q5, mirrored from poll primitive):\n * - `WebhookFetchContext = { subscription, cursor }` — explicitly NO\n * `userId` / `tenantId`. Run-scope identity is closed over by the\n * consumer at queue construction or resolved inside the callback via\n * consumer services. There are no `filters` on the webhook context —\n * filtering is done at registration / on the staging row, not at the\n * port seam (the queue is already filtered by the time the primitive\n * iterates).\n *\n * Long-lived streaming CDC primitives (SFDC Pub-Sub gRPC, Debezium/Kafka,\n * Postgres logical replication) are deferred to `#226-8` — they need a\n * fundamentally different lifecycle (`subscribe(onChange, onError)`,\n * server-paced backpressure, ack-on-yield) and shouldn't be retrofitted\n * into either this primitive or the poll primitive.\n */\n\nimport type { DetectionConfig } from './detection-config.schema';\nimport type {\n Change,\n IChangeSource,\n IntegrationSubscriptionView,\n} from './integration-change-source.protocol';\nimport type {\n ChangeIterator,\n ChangeMiddleware,\n} from './integration-middleware.protocol';\n\n// ============================================================================\n// Cursor + queue callback shapes\n// ============================================================================\n\n/**\n * Opaque webhook cursor shape. Webhook mode typically has a cursor of\n * `{ ts: ISO-string }` (last drained staging-row timestamp) but the\n * primitive treats it as opaque. Consumer-owned queue iterators interpret\n * it however the staging schema needs.\n */\nexport type WebhookCursor = unknown;\n\n/**\n * Context the primitive forwards to the queue iterator. Locked to exactly\n * two fields per the same Q5 reasoning that locks `PollFetchContext` — no\n * `userId` / `tenantId`.\n */\nexport interface WebhookFetchContext {\n readonly subscription: IntegrationSubscriptionView;\n readonly cursor: WebhookCursor | null;\n}\n\n/**\n * Consumer-supplied queue iterator. Returns an async iterable of\n * `{ record }` pairs — the consumer drains the inbound staging queue and\n * emits already-mapped canonical records `T`. The primitive stamps\n * `source: 'webhook'` and `dedupKey` from the record's configured\n * `webhook.eventIdField`; the consumer is the one who decided when a\n * staging row is \"ready\" to drain.\n *\n * Webhook mode has no per-record cursor advance — the staging-row drain\n * order is consumer policy (FIFO by ingestion timestamp, by event id, etc.)\n * and is opaque to the primitive. The orchestrator's last-yielded cursor\n * is whatever the consumer chooses to surface, if anything.\n */\nexport type WebhookFetchCallback<T> = (\n ctx: WebhookFetchContext,\n) => AsyncIterable<{ record: T; cursor?: WebhookCursor }>;\n\n// ============================================================================\n// Constructor options\n// ============================================================================\n\nexport interface WebhookChangeSourceOptions<T> {\n /** Consumer-supplied inbound queue iterator. */\n readonly queue: WebhookFetchCallback<T>;\n /**\n * Parsed detection config. MUST be `mode: 'webhook'`; the constructor\n * throws if a poll config is supplied. Codegen-emitted factories call\n * `DetectionConfigSchema.parse(...)` upstream so this is a safety net,\n * not the primary validation point.\n */\n readonly config: DetectionConfig;\n /**\n * Optional middleware chain. Same shape and composition rules as\n * `PollChangeSource` — first element is the outermost layer.\n */\n readonly middlewares?: ReadonlyArray<ChangeMiddleware<T>>;\n /**\n * Optional human label for run logs (e.g. `'stripe-webhook-charge'`).\n * Defaults to a derived label based on the mapping at construction.\n */\n readonly label?: string;\n}\n\n// ============================================================================\n// WebhookChangeSource<T>\n// ============================================================================\n\nexport class WebhookChangeSource<T> implements IChangeSource<T> {\n public readonly label: string;\n\n private readonly queue: WebhookFetchCallback<T>;\n private readonly externalIdSourceField: string;\n private readonly eventIdSourceField: string;\n private readonly composed: ChangeIterator<T>;\n\n constructor(opts: WebhookChangeSourceOptions<T>) {\n if (opts.config.mode !== 'webhook') {\n throw new Error(\n `WebhookChangeSource requires DetectionConfig.mode === 'webhook'; got '${(opts.config as { mode: string }).mode}'`,\n );\n }\n const config = opts.config;\n\n // Field mapping: locate the canonical `external_id` target — mirrors the\n // poll primitive's contract. Adapters emit records already-mapped; the\n // primitive needs to know which key on T carries the external id so it\n // can stamp `Change.externalId`.\n const externalIdMapping = config.mapping.find(\n (m) => m.target === 'external_id',\n );\n if (!externalIdMapping) {\n throw new Error(\n \"WebhookChangeSource: DetectionConfig.mapping must include an entry with target 'external_id' so emitted Change<T>.externalId can be populated\",\n );\n }\n this.externalIdSourceField = externalIdMapping.target;\n this.eventIdSourceField = config.webhook.eventIdField;\n\n this.queue = opts.queue;\n\n this.label =\n opts.label ?? `webhook-change-source:${externalIdMapping.source}`;\n\n // Compose middleware chain — same shape as PollChangeSource.\n const inner: ChangeIterator<T> = (sub, cur) => this.fetch(sub, cur);\n const middlewares = opts.middlewares ?? [];\n this.composed = middlewares.reduceRight<ChangeIterator<T>>(\n (next, mw) => mw(next),\n inner,\n );\n }\n\n listChanges(\n subscription: IntegrationSubscriptionView,\n cursor: unknown | null,\n ): AsyncIterable<Change<T>> {\n return this.composed(subscription, cursor);\n }\n\n private async *fetch(\n subscription: IntegrationSubscriptionView,\n cursor: unknown | null,\n ): AsyncIterable<Change<T>> {\n const ctx: WebhookFetchContext = {\n subscription,\n cursor: cursor as WebhookCursor | null,\n };\n\n for await (const { record, cursor: nextCursor } of this.queue(ctx)) {\n const externalIdRaw = (record as Record<string, unknown>)[\n this.externalIdSourceField\n ];\n if (typeof externalIdRaw !== 'string' || externalIdRaw.length === 0) {\n throw new Error(\n `WebhookChangeSource: record missing string '${this.externalIdSourceField}' — emitted records MUST carry the canonical external id keyed by the mapping target`,\n );\n }\n const eventIdRaw = (record as Record<string, unknown>)[\n this.eventIdSourceField\n ];\n if (typeof eventIdRaw !== 'string' || eventIdRaw.length === 0) {\n throw new Error(\n `WebhookChangeSource: record missing string '${this.eventIdSourceField}' — webhook records MUST carry the event id (DetectionConfig.webhook.eventIdField) so Change<T>.dedupKey can be populated`,\n );\n }\n\n const change: Change<T> = {\n externalId: externalIdRaw,\n // Webhook mode cannot distinguish create vs. update vs. delete on\n // its own — the orchestrator's diff stage handles classification.\n // Tombstone / soft-delete detection is consumer-driven (same as\n // poll mode — see ADR-033).\n operation: 'updated',\n record,\n cursor: nextCursor ?? null,\n source: 'webhook',\n dedupKey: eventIdRaw,\n };\n yield change;\n }\n }\n}\n"],"mappings":";AAsHO,IAAM,sBAAN,MAAyD;AAAA,EAC9C;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,MAAqC;AAC/C,QAAI,KAAK,OAAO,SAAS,WAAW;AAClC,YAAM,IAAI;AAAA,QACR,yEAA0E,KAAK,OAA4B,IAAI;AAAA,MACjH;AAAA,IACF;AACA,UAAM,SAAS,KAAK;AAMpB,UAAM,oBAAoB,OAAO,QAAQ;AAAA,MACvC,CAAC,MAAM,EAAE,WAAW;AAAA,IACtB;AACA,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,SAAK,wBAAwB,kBAAkB;AAC/C,SAAK,qBAAqB,OAAO,QAAQ;AAEzC,SAAK,QAAQ,KAAK;AAElB,SAAK,QACH,KAAK,SAAS,yBAAyB,kBAAkB,MAAM;AAGjE,UAAM,QAA2B,CAAC,KAAK,QAAQ,KAAK,MAAM,KAAK,GAAG;AAClE,UAAM,cAAc,KAAK,eAAe,CAAC;AACzC,SAAK,WAAW,YAAY;AAAA,MAC1B,CAAC,MAAM,OAAO,GAAG,IAAI;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YACE,cACA,QAC0B;AAC1B,WAAO,KAAK,SAAS,cAAc,MAAM;AAAA,EAC3C;AAAA,EAEA,OAAe,MACb,cACA,QAC0B;AAC1B,UAAM,MAA2B;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAEA,qBAAiB,EAAE,QAAQ,QAAQ,WAAW,KAAK,KAAK,MAAM,GAAG,GAAG;AAClE,YAAM,gBAAiB,OACrB,KAAK,qBACP;AACA,UAAI,OAAO,kBAAkB,YAAY,cAAc,WAAW,GAAG;AACnE,cAAM,IAAI;AAAA,UACR,+CAA+C,KAAK,qBAAqB;AAAA,QAC3E;AAAA,MACF;AACA,YAAM,aAAc,OAClB,KAAK,kBACP;AACA,UAAI,OAAO,eAAe,YAAY,WAAW,WAAW,GAAG;AAC7D,cAAM,IAAI;AAAA,UACR,+CAA+C,KAAK,kBAAkB;AAAA,QACxE;AAAA,MACF;AAEA,YAAM,SAAoB;AAAA,QACxB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,QAKZ,WAAW;AAAA,QACX;AAAA,QACA,QAAQ,cAAc;AAAA,QACtB,QAAQ;AAAA,QACR,UAAU;AAAA,MACZ;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|