Skip to content

Instantly share code, notes, and snippets.

@bendk
Last active February 16, 2023 17:34
Show Gist options
  • Save bendk/5126b741bf3d22fbaead5dd34d3423a1 to your computer and use it in GitHub Desktop.
Save bendk/5126b741bf3d22fbaead5dd34d3423a1 to your computer and use it in GitHub Desktop.
/// Addresses sync record
///
/// The every field in the record contributes to the key. If there are changes both locally and
/// remotely, then we fork the record into two.
///
/// Key handling quirks:
/// * If the changes are on different fields, then we merge them rather than fork
/// * We only fork records, we don't merge records if they change to be the same as another record.
#[synckit::record]
struct AddressRecord {
#[key]
given_name: String,
#[key]
additional_name: String,
#[key]
family_name: String,
#[key]
organization: String,
#[key]
street_address: String,
#[key]
address_level3: String,
#[key]
address_level2: String,
#[key]
address_level1: String,
#[key]
postal_code: String,
#[key]
country: String,
#[key]
tel: String,
#[key]
email: String,
// metadata (which isn't kebab-case for some historical reason...)
#[key, payload_name = "timeCreated"]
time_created: Timestamp,
#[key, payload_name = "timeLastUsed"]
time_last_used: Timestamp,
#[key, payload_name = "timeLastModified"]
time_last_modified: Timestamp,
#[key, payload_name = "timesUsed"]
times_used: i64,
#[key]
version: u32, // always 3 for addresses
}
/// Credit card sync record
///
/// The every field in the record contributes to the key. If there are changes both locally and
/// remotely, then we fork the record into two.
///
/// Key handling quirks:
/// * If the changes are on different fields, then we merge them rather than fork
/// * We only fork records, we don't merge records if they change to be the same as another record.
#[synckit::record]
struct CreditCardRecord {
#[key]
cc_name: String,
#[key]
cc_number: String,
#[key]
cc_exp_month: i64,
#[key]
cc_exp_year: i64,
#[key]
cc_type: String,
// metadata (which isn't kebab-case for some historical reason...)
#[key, payload_name = "timeCreated"]
time_created: Timestamp,
#[key, payload_name = "timeLastUsed"]
time_last_used: Timestamp,
#[key, payload_name = "timeLastModified"]
time_last_modified: Timestamp,
#[key, payload_name = "timesUsed"]
times_used: i64,
#[key]
version: u32, // always 3 for credit-cards
}
/// History sync record
///
/// Quirks:
/// * visits is merged mostly like a max-n-set, but is implemented with special code. See
/// `plan_incoming_record()` for details.
#[synckit::record]
struct HistoryRecord {
#[payload_name = "id"]
guid: SyncGuid,
#[key]
hist_uri: String,
#[merge_type(take_remote)]
title: String,
#[merge_type(max_n_set(20))]
visits: Vec<HistoryRecordVisit>,
}
/// Item in the `visits` list
#[synckit::record_item]
struct HistoryRecordVisit {
date: ServerVisitTimestamp,
#[payload_name="type"]
transition: u8,
}
/// Logins sync record
///
/// Key handling quirks:
///
/// * We only match up logins by the key when the local record has not been synced. For
/// records that were already synced if the key changes both locally and remotely (i.e. the
/// user edited the username in both places), then we merge those changes rather than
/// forking the record. Similarly, if synced records with different guids change to have the
/// same key, we don't merge them.
/// * There's special handling for the port on `form_sumbit_url`. See `find_dupe_login()` for
/// details.
#[synckit::record]
struct LogicRecord {
guid: Guid,
#[key, merge_type(last_writer_wins)]
hostname: String,
// Note: `form_submit_url` and `http_realm` are mutually exclusive. One will be non-null and the other will be null.
#[key, merge_type(last_writer_wins)]
form_submit_url: Option<String>,
#[key, merge_type(last_writer_wins)]
http_realm: Option<String>,
#[key, merge_type(last_writer_wins)]
username: String,
#[merge_type(last_writer_wins)]
password: String,
#[merge_type(last_writer_wins)]
username_field: String,
#[merge_type(last_writer_wins)]
password_field: String,
#[merge_type(max)]
time_created: i64,
#[merge_type(max)]
time_password_changed: i64,
#[merge_type(counter)]
time_last_used: i64,
#[merge_type(counter)]
times_used: i64,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment