Remote / foldkit-remote-server

EntityWriter

interface · packages/remote-server/src/index.ts:163

interface EntityWriter<P, R = never> {
  readonly entity: string
  readonly update: (context: {
    readonly id: string
    readonly values: Readonly<Record<string, unknown>>
    readonly links: Readonly<Record<string, Option.Option<EntityRef>>>
    readonly expect: Option.Option<{
      readonly field: string
      readonly revision: unknown
    }>
    readonly principal: P
  }) => Effect.Effect<
    Option.Option<Readonly<Record<string, unknown>>>,
    RemoteServerError | RemoteForbidden,
    R
  >
  readonly insert: (context: {
    readonly id: string
    readonly values: Readonly<Record<string, unknown>>
    readonly links: Readonly<Record<string, Option.Option<EntityRef>>>
    readonly principal: P
  }) => Effect.Effect<
    Readonly<Record<string, unknown>>,
    RemoteServerError | RemoteForbidden,
    R
  >
  readonly delete: (context: {
    readonly id: string
    readonly expect: Option.Option<{
      readonly field: string
      readonly revision: unknown
    }>
    readonly principal: P
  }) => Effect.Effect<
    'deleted' | 'absent' | 'moved',
    RemoteServerError | RemoteForbidden,
    R
  >
  readonly read?: (context: {
    readonly id: string
    readonly fields: ReadonlyArray<string>
    readonly principal: P
  }) => Effect.Effect<
    Option.Option<Readonly<Record<string, unknown>>>,
    RemoteServerError,
    R
  >
  readonly linked?: (context: {
    readonly id: string
    readonly relations: ReadonlyArray<string>
  }) => Effect.Effect<
    Option.Option<Readonly<Record<string, unknown>>>,
    RemoteServerError,
    R
  >
}

Where a declared write lands: one row's new values, encoded as the store holds them. With expect, the row is written only while its revision is still that value, and the revision moves on with the write. The row as written answers; none when no row matched.

In the guides

Members

EntityWriter.entity

property · packages/remote-server/src/index.ts:164

readonly entity: string

EntityWriter.update

property · packages/remote-server/src/index.ts:165

readonly update: (context: {
  readonly id: string
  readonly values: Readonly<Record<string, unknown>>
  readonly links: Readonly<Record<string, Option.Option<EntityRef>>>
  readonly expect: Option.Option<{
    readonly field: string
    readonly revision: unknown
  }>
  readonly principal: P
}) => Effect.Effect<
  Option.Option<Readonly<Record<string, unknown>>>,
  RemoteServerError | RemoteForbidden,
  R
>

EntityWriter.insert

property · packages/remote-server/src/index.ts:182

readonly insert: (context: {
  readonly id: string
  readonly values: Readonly<Record<string, unknown>>
  readonly links: Readonly<Record<string, Option.Option<EntityRef>>>
  readonly principal: P
}) => Effect.Effect<
  Readonly<Record<string, unknown>>,
  RemoteServerError | RemoteForbidden,
  R
>

Inserts the row, or finds one already there under that id holding what it writes (a retry); answers the row as it is. Fails when the id holds any other row.

EntityWriter.delete

property · packages/remote-server/src/index.ts:193

readonly delete: (context: {
  readonly id: string
  readonly expect: Option.Option<{
    readonly field: string
    readonly revision: unknown
  }>
  readonly principal: P
}) => Effect.Effect<
  'deleted' | 'absent' | 'moved',
  RemoteServerError | RemoteForbidden,
  R
>

Deletes the row, while it is still at the revision when one is expected: deleted, absent (no row, so nothing to delete; a retry's case), or moved (the row is there at another revision, and stays).

EntityWriter.read

property · packages/remote-server/src/index.ts:204

readonly read?: (context: {
  readonly id: string
  readonly fields: ReadonlyArray<string>
  readonly principal: P
}) => Effect.Effect<
  Option.Option<Readonly<Record<string, unknown>>>,
  RemoteServerError,
  R
>

The row as principal may see it, under the read rule its Source applies: none when there is no such row, or it is hidden. Given, a write's answer is read back through it, so an answer never shows its writer a row it may not read, and a row the write hid from them answers as deleted.

EntityWriter.linked

property · packages/remote-server/src/index.ts:215

readonly linked?: (context: {
  readonly id: string
  readonly relations: ReadonlyArray<string>
}) => Effect.Effect<
  Option.Option<Readonly<Record<string, unknown>>>,
  RemoteServerError,
  R
>

Each of relations' links as stored, by ref key ('Project:p1') or null, whatever a reader may see of the row it points at; none when there is no such row. A guard reads it to tell a write that unlinks a row hidden from its writer from one that changes nothing.