Skip to content

Commit ef9a1e6

Browse files
committed
estuary-cdk: add SnapshotResource subclass of Resource
Snapshot bindings always use the same key (`/_meta/row_id`), initial state (`ResourceState()`), and reduction strategy (`lastWriteWins`). `SnapshotResource` encodes these invariants as defaults so connectors don't need to repeat them.
1 parent 5a2ba7f commit ef9a1e6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

estuary-cdk/estuary_cdk/capture/common.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import asyncio
33
import functools
44
from enum import Enum, StrEnum
5-
from dataclasses import dataclass
5+
from dataclasses import dataclass, field
66
from datetime import UTC, datetime, timedelta
77
import inspect
88
from logging import Logger
@@ -475,6 +475,20 @@ class FixedSchema:
475475
disable: bool = False
476476

477477

478+
@dataclass(kw_only=True)
479+
class SnapshotResource(Resource[_BaseDocument, _BaseResourceConfig, ResourceState]):
480+
"""A Resource for snapshot bindings with standard defaults that
481+
work well with the rest of the CDK and Estuary Flow platform.
482+
483+
Sets key to /_meta/row_id (required for CDK deletion inference),
484+
initial_state to an empty ResourceState, and reduction_strategy to
485+
lastWriteWins — the invariant choices for all snapshot bindings.
486+
"""
487+
488+
key: list[str] = field(default_factory=lambda: ["/_meta/row_id"])
489+
initial_state: ResourceState = field(default_factory=ResourceState)
490+
491+
478492
def discovered(
479493
resources: list["Resource[_BaseDocument, _BaseResourceConfig, _BaseResourceState]"],
480494
) -> response.Discovered[_BaseResourceConfig]:

0 commit comments

Comments
 (0)