Sync / foldkit-sync

DefinedSync

interface · packages/sync/src/make.ts:322

interface DefinedSync<
  AppModel,
  Fields extends Schema.Struct.Fields,
  Message,
  Ms extends readonly unknown[],
  Principal = unknown,
  Authorized extends boolean = false,
  SMs extends readonly unknown[] = [],
  LawIds extends string = string,
> extends Sync<Message, Schema.Struct.Type<Fields>, MsgOf<Ms>> {
  readonly surface: Surface<
    AppModel,
    Schema.Struct.Type<Fields>,
    MsgOf<Ms>,
    void
  >
  readonly projection: WritableProjection<AppModel, Fields>
  readonly footprints?: Readonly<
    Partial<Record<TagOf<Ms[number] | SMs[number]>, Footprint>>
  >
  readonly replay: (
    shared: Schema.Struct.Type<Fields>,
    message: Message,
  ) => Schema.Struct.Type<Fields>
  readonly live: (model: AppModel, message: Message) => Option.Option<AppModel>
  readonly messages: Ms
  readonly serverOnlyMessages: SMs
  readonly laws: {
    readonly [Id in LawIds]: DeclaredLaw<Id>
  }
  readonly judge: (
    before: Schema.Struct.Type<Fields>,
    after: Schema.Struct.Type<Fields>,
  ) => Option.Option<DeclaredLaw<LawIds>>
  readonly contract: Contract
  readonly wiring: () => Wiring<AppModel, never>
  readonly journalContract: () => Authorized extends true
    ? PolicyJournalContract<Operation, Schema.Struct.Type<Fields>, Principal> &
        Required<
          Pick<
            PolicyJournalContract<
              Operation,
              Schema.Struct.Type<Fields>,
              Principal
            >,
            'authorize'
          >
        >
    : PolicyJournalContract<Operation, Schema.Struct.Type<Fields>, Principal>
}

The value make returns: the low-level Sync protocol plus the writable projection, the declared Messages, and a read-only Surface over the projection. Exported so a consumer can name the type.

Members

DefinedSync.surface

property · packages/sync/src/make.ts:335

readonly surface: Surface<
  AppModel,
  Schema.Struct.Type<Fields>,
  MsgOf<Ms>,
  void
>

DefinedSync.projection

property · packages/sync/src/make.ts:336

readonly projection: WritableProjection<AppModel, Fields>

DefinedSync.footprints

property · packages/sync/src/make.ts:338

readonly footprints?: Readonly<
  Partial<Record<TagOf<Ms[number] | SMs[number]>, Footprint>>
>

Static paths of the transitions this document executes, keyed by durable or server-only tag.

DefinedSync.replay

property · packages/sync/src/make.ts:340

readonly replay: (
  shared: Schema.Struct.Type<Fields>,
  message: Message,
) => Schema.Struct.Type<Fields>

Replays a declared transition, falling back to the custom replay or the application's update.

DefinedSync.live

property · packages/sync/src/make.ts:345

readonly live: (model: AppModel, message: Message) => Option.Option<AppModel>

DeclaredReplay's live: what the mount applies for a Message with a declared transition.

DefinedSync.messages

property · packages/sync/src/make.ts:347

readonly messages: Ms

The durable constructors: what a replica submits.

DefinedSync.serverOnlyMessages

property · packages/sync/src/make.ts:349

readonly serverOnlyMessages: SMs

The server-only constructors: what only the server appends.

DefinedSync.laws

property · packages/sync/src/make.ts:351

readonly laws: {
  readonly [Id in LawIds]: DeclaredLaw<Id>
}

The declared laws, by id: what Sync.isInvalidBy matches a refusal against.

DefinedSync.judge

property · packages/sync/src/make.ts:357

readonly judge: (
  before: Schema.Struct.Type<Fields>,
  after: Schema.Struct.Type<Fields>,
) => Option.Option<DeclaredLaw<LawIds>>

The first law the step from before to after breaks, or none: what the journal and submit run. Run it over stored snapshots (judge(s, s)) to audit them before deploying a new law.

DefinedSync.contract

property · packages/sync/src/make.ts:362

readonly contract: Contract

For Module: this contract owns the shared projection's paths and records the durable and server-only tags.

DefinedSync.wiring

property · packages/sync/src/make.ts:368

readonly wiring: () => Wiring<AppModel, never>

How this contract joins an assembly: contract-only, so the Module sees it. It routes nothing, runs nothing, and subscribes to nothing; Sync owns the runtime through mount rather than joining it.

DefinedSync.journalContract

property · packages/sync/src/make.ts:370

readonly journalContract: () => Authorized extends true
  ? PolicyJournalContract<Operation, Schema.Struct.Type<Fields>, Principal> &
      Required<
        Pick<
          PolicyJournalContract<
            Operation,
            Schema.Struct.Type<Fields>,
            Principal
          >,
          'authorize'
        >
      >
  : PolicyJournalContract<Operation, Schema.Struct.Type<Fields>, Principal>

The durable journal's codecs, reducer, and, when declared, authorization.