Skip to main content Link Search Menu Expand Document (external link)

KeyValueStore.ts overview

Since v1.0.0


Exports Grouped by Category


combinators

prefix

Signature

declare const prefix: {
  (prefix: string): <S extends KeyValueStore.AnyStore>(self: S) => S
  <S extends KeyValueStore.AnyStore>(self: S, prefix: string): S
}

Source

Since v1.0.0

constructors

make

Signature

declare const make: (
  impl: Omit<KeyValueStore, typeof TypeId | "has" | "modify" | "isEmpty" | "forSchema"> & Partial<KeyValueStore>
) => KeyValueStore

Source

Since v1.0.0

makeStringOnly

Signature

declare const makeStringOnly: (
  impl: Pick<KeyValueStore, "get" | "remove" | "clear" | "size"> &
    Partial<Omit<KeyValueStore, "set">> & {
      readonly set: (key: string, value: string) => Effect.Effect<void, PlatformError.PlatformError>
    }
) => KeyValueStore

Source

Since v1.0.0

layers

layerFileSystem

Signature

declare const layerFileSystem: (
  directory: string
) => Layer.Layer<KeyValueStore, PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>

Source

Since v1.0.0

layerMemory

Signature

declare const layerMemory: Layer.Layer<KeyValueStore>

Source

Since v1.0.0

layerSchema

Signature

declare const layerSchema: <A, I, R>(
  schema: Schema.Schema<A, I, R>,
  tagIdentifier: string
) => {
  readonly tag: Context.Tag<SchemaStore<A, R>, SchemaStore<A, R>>
  readonly layer: Layer.Layer<SchemaStore<A, R>, never, KeyValueStore>
}

Source

Since v1.0.0

layerStorage

Creates an KeyValueStorage from an instance of the Storage api.

See

  • https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API

Signature

declare const layerStorage: (evaluate: LazyArg<Storage>) => Layer.Layer<KeyValueStore>

Source

Since v1.0.0

models

KeyValueStore (interface)

Signature

export interface KeyValueStore {
  readonly [TypeId]: TypeId
  /**
   * Returns the value of the specified key if it exists.
   */
  readonly get: (key: string) => Effect.Effect<Option.Option<string>, PlatformError.PlatformError>

  /**
   * Returns the value of the specified key if it exists.
   */
  readonly getUint8Array: (key: string) => Effect.Effect<Option.Option<Uint8Array>, PlatformError.PlatformError>

  /**
   * Sets the value of the specified key.
   */
  readonly set: (key: string, value: string | Uint8Array) => Effect.Effect<void, PlatformError.PlatformError>

  /**
   * Removes the specified key.
   */
  readonly remove: (key: string) => Effect.Effect<void, PlatformError.PlatformError>

  /**
   * Removes all entries.
   */
  readonly clear: Effect.Effect<void, PlatformError.PlatformError>

  /**
   * Returns the number of entries.
   */
  readonly size: Effect.Effect<number, PlatformError.PlatformError>

  /**
   * Updates the value of the specified key if it exists.
   */
  readonly modify: (
    key: string,
    f: (value: string) => string
  ) => Effect.Effect<Option.Option<string>, PlatformError.PlatformError>

  /**
   * Updates the value of the specified key if it exists.
   */
  readonly modifyUint8Array: (
    key: string,
    f: (value: Uint8Array) => Uint8Array
  ) => Effect.Effect<Option.Option<Uint8Array>, PlatformError.PlatformError>

  /**
   * Returns true if the KeyValueStore contains the specified key.
   */
  readonly has: (key: string) => Effect.Effect<boolean, PlatformError.PlatformError>

  /**
   * Checks if the KeyValueStore contains any entries.
   */
  readonly isEmpty: Effect.Effect<boolean, PlatformError.PlatformError>

  /**
   * Create a SchemaStore for the specified schema.
   */
  readonly forSchema: <A, I, R>(schema: Schema.Schema<A, I, R>) => SchemaStore<A, R>
}

Source

Since v1.0.0

SchemaStore (interface)

Signature

export interface SchemaStore<A, R> {
  readonly [SchemaStoreTypeId]: SchemaStoreTypeId
  /**
   * Returns the value of the specified key if it exists.
   */
  readonly get: (
    key: string
  ) => Effect.Effect<Option.Option<A>, PlatformError.PlatformError | ParseResult.ParseError, R>

  /**
   * Sets the value of the specified key.
   */
  readonly set: (key: string, value: A) => Effect.Effect<void, PlatformError.PlatformError | ParseResult.ParseError, R>

  /**
   * Removes the specified key.
   */
  readonly remove: (key: string) => Effect.Effect<void, PlatformError.PlatformError>

  /**
   * Removes all entries.
   */
  readonly clear: Effect.Effect<void, PlatformError.PlatformError>

  /**
   * Returns the number of entries.
   */
  readonly size: Effect.Effect<number, PlatformError.PlatformError>

  /**
   * Updates the value of the specified key if it exists.
   */
  readonly modify: (
    key: string,
    f: (value: A) => A
  ) => Effect.Effect<Option.Option<A>, PlatformError.PlatformError | ParseResult.ParseError, R>

  /**
   * Returns true if the KeyValueStore contains the specified key.
   */
  readonly has: (key: string) => Effect.Effect<boolean, PlatformError.PlatformError>

  /**
   * Checks if the KeyValueStore contains any entries.
   */
  readonly isEmpty: Effect.Effect<boolean, PlatformError.PlatformError>
}

Source

Since v1.0.0

tags

KeyValueStore

Signature

declare const KeyValueStore: Context.Tag<KeyValueStore, KeyValueStore>

Source

Since v1.0.0

type id

SchemaStoreTypeId

Signature

declare const SchemaStoreTypeId: unique symbol

Source

Since v1.0.0

SchemaStoreTypeId (type alias)

Signature

type SchemaStoreTypeId = typeof SchemaStoreTypeId

Source

Since v1.0.0

TypeId

Signature

declare const TypeId: unique symbol

Source

Since v1.0.0

TypeId (type alias)

Signature

type TypeId = typeof TypeId

Source

Since v1.0.0

utils

KeyValueStore (namespace)

Source

Since v1.0.0

AnyStore (type alias)

Signature

type AnyStore = KeyValueStore | SchemaStore<any, any>

Source

Since v1.0.0