Files
simstudioai--sim/apps/sim/lib/data-drains/serializers.ts
T
wehub-resource-sync d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

55 lines
2.0 KiB
TypeScript

import type { dataDrainRuns, dataDrains } from '@sim/db/schema'
import { type DataDrain, type DataDrainRun, dataDrainSchema } from '@/lib/api/contracts/data-drains'
import { getDestination } from '@/lib/data-drains/destinations/registry'
type DataDrainRow = typeof dataDrains.$inferSelect
type DataDrainRunRow = typeof dataDrainRuns.$inferSelect
/**
* Projects a DB row into the public `DataDrain` wire shape. Strips the
* encrypted credentials column and normalizes timestamps to ISO strings so
* clients receive a stable, schema-validated payload.
*
* The stored `destinationConfig` is JSONB and is re-validated against the
* destination's typed config schema before serialization so unexpected shapes
* surface as errors instead of leaking through the response.
*/
export function serializeDrain(row: DataDrainRow): DataDrain {
const destinationConfig = getDestination(row.destinationType).configSchema.parse(
row.destinationConfig
)
return dataDrainSchema.parse({
id: row.id,
organizationId: row.organizationId,
name: row.name,
source: row.source,
scheduleCadence: row.scheduleCadence,
enabled: row.enabled,
cursor: row.cursor,
lastRunAt: row.lastRunAt ? row.lastRunAt.toISOString() : null,
lastSuccessAt: row.lastSuccessAt ? row.lastSuccessAt.toISOString() : null,
createdBy: row.createdBy,
createdAt: row.createdAt.toISOString(),
updatedAt: row.updatedAt.toISOString(),
destinationType: row.destinationType,
destinationConfig,
})
}
export function serializeDrainRun(row: DataDrainRunRow): DataDrainRun {
return {
id: row.id,
drainId: row.drainId,
status: row.status,
trigger: row.trigger,
startedAt: row.startedAt.toISOString(),
finishedAt: row.finishedAt ? row.finishedAt.toISOString() : null,
rowsExported: row.rowsExported,
bytesWritten: row.bytesWritten,
cursorBefore: row.cursorBefore,
cursorAfter: row.cursorAfter,
error: row.error,
locators: row.locators ?? [],
}
}