shopify_draft_proxy/state/synthetic_identity

Mirrors src/state/synthetic-identity.ts.

The TypeScript class mutates two counters in place: nextSyntheticId and nextSyntheticTime. Gleam values are immutable, so each generator function returns the new value paired with an updated registry; callers thread the registry through their own state.

The TypeScript proxy keeps a single registry alive for the lifetime of the DraftProxy instance. When we wire the registry into the Gleam port’s request pipeline (Phase 2 task #15), the dispatcher will own the registry and update it once per mutation.

Types

Reasons restore_state can refuse a dump.

pub type RestoreError {
  InvalidSyntheticId(Int)
  InvalidSyntheticTimestamp(String)
}

Constructors

  • InvalidSyntheticId(Int)

    next_synthetic_id was less than 1 — the TS version requires a positive integer.

  • InvalidSyntheticTimestamp(String)

    The ISO timestamp string failed to parse on the host platform.

Two monotonically increasing counters: an integer id used to mint fresh gid://shopify/... resource identifiers, and a millisecond epoch used to mint fresh createdAt/updatedAt-style timestamps.

pub type SyntheticIdentityRegistry {
  SyntheticIdentityRegistry(
    next_synthetic_id: Int,
    next_synthetic_time: Int,
  )
}

Constructors

  • SyntheticIdentityRegistry(
      next_synthetic_id: Int,
      next_synthetic_time: Int,
    )

Versioned dump for state restoration. The TypeScript counterpart stores the timestamp as an ISO string; we mirror that shape so the JSON form is byte-identical between implementations.

pub type SyntheticIdentityStateDumpV1 {
  SyntheticIdentityStateDumpV1(
    next_synthetic_id: Int,
    next_synthetic_timestamp: String,
  )
}

Constructors

  • SyntheticIdentityStateDumpV1(
      next_synthetic_id: Int,
      next_synthetic_timestamp: String,
    )

Values

pub fn dump_state(
  registry: SyntheticIdentityRegistry,
) -> SyntheticIdentityStateDumpV1

Snapshot the registry into a versioned dump record. Mirrors dumpState.

pub fn is_proxy_synthetic_gid(value: String) -> Bool

Detect a gid produced by make_proxy_synthetic_gid. Mirrors isProxySyntheticGid.

pub fn make_proxy_synthetic_gid(
  registry: SyntheticIdentityRegistry,
  resource_type: String,
) -> #(String, SyntheticIdentityRegistry)

Mint a fresh gid tagged with the proxy’s synthetic marker. Mirrors makeProxySyntheticGid. Used for entities that the proxy fabricates in response to mutations so it can later spot them in nodes(ids:…) queries.

pub fn make_synthetic_gid(
  registry: SyntheticIdentityRegistry,
  resource_type: String,
) -> #(String, SyntheticIdentityRegistry)

Mint a fresh gid://shopify/<resourceType>/<id>. Returns the new gid and the registry with next_synthetic_id incremented.

pub fn make_synthetic_timestamp(
  registry: SyntheticIdentityRegistry,
) -> #(String, SyntheticIdentityRegistry)

Mint a fresh ISO 8601 timestamp. Returns the timestamp and the registry with next_synthetic_time advanced by one second, matching makeSyntheticTimestamp in TS.

pub fn new() -> SyntheticIdentityRegistry

Fresh registry, equivalent to new SyntheticIdentityRegistry() in TS.

pub fn reset(
  registry: SyntheticIdentityRegistry,
) -> SyntheticIdentityRegistry

Reset both counters to their starting values. Mirrors reset().

pub fn restore_state(
  dump: SyntheticIdentityStateDumpV1,
) -> Result(SyntheticIdentityRegistry, RestoreError)

Build a registry from a dump, validating the inputs. Mirrors restoreState but returns a Result instead of throwing, since Gleam doesn’t have exceptions.

Search Document