Sync records
A sync reads website data on a schedule and publishes records your app can consume.
integrations/atlas-demo/syncs/bookings.ts:
import { randomUUID } from "node:crypto";
import { createSync } from "@browserlayer/sdk";
import { z } from "zod";
import listBookings from "../connector/flows/list-bookings.js";
import { publicBookings } from "../models/bookings.js";
import { Booking } from "../models/booking.js";
export default createSync({
description:
"Keep the application's bookings current, including cancellations and deletions.",
connection: "required",
schedule: "every 30 seconds",
model: Booking,
checkpoint: z.null(),
async exec(ctx) {
const scan = await ctx.step("scan", async () => randomUUID());
const source = await ctx.run(listBookings, {});
const records = await publicBookings(ctx, source);
await ctx.publish("snapshot", records, {
checkpoint: null,
scan,
completeScan: true,
});
},
});This example publishes a complete snapshot. The connector and model are supplied by the Atlas tutorial.
Inspect and control locally
browserlayer syncs list <connection-id> --local
browserlayer syncs trigger <connection-id> bookings --local
browserlayer syncs records <connection-id> bookings --local
browserlayer syncs pause <connection-id> bookings --local
browserlayer syncs start <connection-id> bookings --localKeep browserlayer start running. Connected accounts get schedules automatically. Waiting runs prevent overlap. pause prevents the next occurrence; it does not cancel the current run. trigger enables the schedule and makes it due now.
Use the same commands with --env development after deploying.
| Option | Required | Example |
|---|---|---|
connection | Yes | "required" |
schedule | Yes | "every 5 minutes" |
model | Yes | Zod object with string id |
checkpoint | Yes | z.null() or a source progress schema |
Next: Checkpoints and deletions, then consume records.