rmapi-js
    Preparing search index...

    Class FakeCloud

    an in-memory reMarkable account, answering at the testHosts

    Give a client its fetch, and its connect for notifications, with the test hosts and a session from sessionToken. With checks on, the default, it logs every request and refuses what the account refuses: a token that proves nothing, a blob whose name, checksum or hash is wrong, a root write at another generation or naming a blob never sent. Off, as for a benchmark, it logs nothing and only refuses a root write at another generation.

    Seed it with seeding, break it with the failure switches, and read back what a client left with items, file and isWhole. A switch that takes a count replaces what is left of the last one, so 0 turns it off.

    const cloud = new FakeCloud();
    cloud.seeding().folder(cloud.newItemId(), "reading").put();
    const client = Client.fromSession(SessionToken.parse(sessionToken()), {
    ...testHosts(),
    fetch: cloud.fetch,
    connect: cloud.connect,
    });
    Index
    • get accountId(): string

      the account every token this cloud issues names

      Returns string

    • get deviceId(): string

      the device this cloud's device token names

      Returns string

    • get generation(): number

      the account's generation, which each move of the root raises

      Returns number

    • get openSockets(): number

      how many notification sockets are open

      Returns number

    • answer the reads of the blob hash again

      Parameters

      • hash: string

      Returns void

    • tell every open notification socket that device sent event

      Parameters

      • device: string
      • event: string = "SyncComplete"

      Returns void

    • answer the next request with status and body, doing nothing; queued in order

      Parameters

      • status: number
      • body: Uint8Array = ...

      Returns void

    • the blob stored under hash, whether seeded or sent by a client

      Parameters

      • hash: string

      Returns Uint8Array<ArrayBufferLike> | undefined

    • answer the next count session fetches with a 503, as a busy auth host does

      Parameters

      • count: number

      Returns void

    • fail the next count requests at the transport before acting on them

      Parameters

      • count: number

      Returns void

    • answer every request that carries a session token issued so far with a 401

      Returns void

    • answer every request that carries the session token token with a 401, as once it expired

      Parameters

      • token: string

      Returns void

    • the account's http, as a client's fetch

      Parameters

      • url: string | URL
      • init: RequestInit = {}

      Returns Promise<Response>

    • the item id's file named name in full, such as <id>.content, if it has one

      Parameters

      • id: string
      • name: string

      Returns Uint8Array<ArrayBufferLike> | undefined

    • the names of the item id's files, as its index lists them

      Parameters

      • id: string

      Returns string[]

    • forget every blob larger than bytes, so large uploads are not kept

      Parameters

      • bytes: number

      Returns void

    • the headers of every notification socket handshake, in order

      Returns [string, string][][]

    • close every open notification socket from the account's side, as it does every few minutes

      Returns void

    • whether every blob the account's indexes name is stored

      Returns boolean

    • act on the next count requests and then fail each at the transport, the answer lost

      Parameters

      • count: number

      Returns void

    • a new item id, minted in order, so a test makes the same ids each run

      Returns string

    • answer every read of the blob hash with a 503, as a server failing one file would

      Parameters

      • hash: string

      Returns void

    • answer the next count requests other than a token's with a 401, as for an expired session

      Parameters

      • count: number

      Returns void

    • drop the item id's file name, as a half-written upload leaves it, moving the generation, and give the hash of the item's new index

      Parameters

      • id: string
      • name: string

      Returns string

    • remove the item id from the root index, as a purge by another device does

      Parameters

      • id: string

      Returns void

    • forget the requests sent and their counts

      Returns void

    • answer every session fetch with a 401, as for a device token that was revoked

      Returns void

    • answer the next count requests with a 503, doing nothing

      Parameters

      • count: number

      Returns void

    • answer the next count root reads with the root before the latest move

      Parameters

      • count: number

      Returns void

    • whether a root write that asks to tell other devices sends a sync event to every open socket (default: true)

      Parameters

      • notify: boolean

      Returns void

    • fail every request and every socket at the transport, as with no network, or stop

      Parameters

      • offline: boolean

      Returns void

    • make the next count root writes lose, as though another device wrote first

      Parameters

      • count: number

      Returns void

    • answer the next count blob reads with a 200 and only the first half of the blob

      Parameters

      • count: number

      Returns void

    • write the item id's file name as another device would, moving the generation, and give the hash of the item's new index

      Parameters

      • id: string
      • name: string
      • bytes: Uint8Array

      Returns string