/** * @since 1.0.0 */ import type * as Context from "effect/Context" import type * as Effect from "effect/Effect" import type { LazyArg } from "effect/Function" import type * as Layer from "effect/Layer" import type * as Option from "effect/Option" import type * as ParseResult from "effect/ParseResult" import type * as Schema from "effect/Schema" import type * as PlatformError from "./Error.js" import type * as FileSystem from "./FileSystem.js" import * as internal from "./internal/keyValueStore.js" import type * as Path from "./Path.js" /** * @since 1.0.0 * @category type id */ export const TypeId: unique symbol = internal.TypeId /** * @since 1.0.0 * @category type id */ export type TypeId = typeof TypeId /** * @since 1.0.0 * @category models */ export interface KeyValueStore { readonly [TypeId]: TypeId /** * Returns the value of the specified key if it exists. */ readonly get: (key: string) => Effect.Effect, PlatformError.PlatformError> /** * Returns the value of the specified key if it exists. */ readonly getUint8Array: (key: string) => Effect.Effect, PlatformError.PlatformError> /** * Sets the value of the specified key. */ readonly set: (key: string, value: string | Uint8Array) => Effect.Effect /** * Removes the specified key. */ readonly remove: (key: string) => Effect.Effect /** * Removes all entries. */ readonly clear: Effect.Effect /** * Returns the number of entries. */ readonly size: Effect.Effect /** * Updates the value of the specified key if it exists. */ readonly modify: ( key: string, f: (value: string) => string ) => Effect.Effect, PlatformError.PlatformError> /** * Updates the value of the specified key if it exists. */ readonly modifyUint8Array: ( key: string, f: (value: Uint8Array) => Uint8Array ) => Effect.Effect, PlatformError.PlatformError> /** * Returns true if the KeyValueStore contains the specified key. */ readonly has: (key: string) => Effect.Effect /** * Checks if the KeyValueStore contains any entries. */ readonly isEmpty: Effect.Effect /** * Create a SchemaStore for the specified schema. */ readonly forSchema: (schema: Schema.Schema) => SchemaStore } /** * @since 1.0.0 */ export declare namespace KeyValueStore { /** * @since 1.0.0 */ export type AnyStore = KeyValueStore | SchemaStore } /** * @since 1.0.0 * @category tags */ export const KeyValueStore: Context.Tag = internal.keyValueStoreTag /** * @since 1.0.0 * @category constructors */ export const make: ( impl: & Omit & Partial ) => KeyValueStore = internal.make /** * @since 1.0.0 * @category constructors */ export const makeStringOnly: ( impl: Pick & Partial> & { readonly set: (key: string, value: string) => Effect.Effect } ) => KeyValueStore = internal.makeStringOnly /** * @since 1.0.0 * @category combinators */ export const prefix: { /** * @since 1.0.0 * @category combinators */ (prefix: string): (self: S) => S /** * @since 1.0.0 * @category combinators */ (self: S, prefix: string): S } = internal.prefix /** * @since 1.0.0 * @category layers */ export const layerMemory: Layer.Layer = internal.layerMemory /** * Provides a file-backed key-value store in the specified directory. * * Keys are percent-encoded as single file names. Empty keys, `.` and `..` are * rejected. Keys are only guaranteed to be distinct on case-sensitive file * systems. * * `clear` removes the directory recursively, so it must not be shared with * unrelated data. * * @since 1.0.0 * @category layers */ export const layerFileSystem: ( directory: string ) => Layer.Layer = internal.layerFileSystem /** * @since 1.0.0 * @category type id */ export const SchemaStoreTypeId: unique symbol = internal.SchemaStoreTypeId /** * @since 1.0.0 * @category type id */ export type SchemaStoreTypeId = typeof SchemaStoreTypeId /** * @since 1.0.0 * @category models */ export interface SchemaStore { readonly [SchemaStoreTypeId]: SchemaStoreTypeId /** * Returns the value of the specified key if it exists. */ readonly get: ( key: string ) => Effect.Effect, PlatformError.PlatformError | ParseResult.ParseError, R> /** * Sets the value of the specified key. */ readonly set: ( key: string, value: A ) => Effect.Effect /** * Removes the specified key. */ readonly remove: (key: string) => Effect.Effect /** * Removes all entries. */ readonly clear: Effect.Effect /** * Returns the number of entries. */ readonly size: Effect.Effect /** * Updates the value of the specified key if it exists. */ readonly modify: ( key: string, f: (value: A) => A ) => Effect.Effect, PlatformError.PlatformError | ParseResult.ParseError, R> /** * Returns true if the KeyValueStore contains the specified key. */ readonly has: (key: string) => Effect.Effect /** * Checks if the KeyValueStore contains any entries. */ readonly isEmpty: Effect.Effect } /** * @since 1.0.0 * @category layers */ export const layerSchema: ( schema: Schema.Schema, tagIdentifier: string ) => { readonly tag: Context.Tag, SchemaStore> readonly layer: Layer.Layer, never, KeyValueStore> } = internal.layerSchema /** * Creates an KeyValueStorage from an instance of the `Storage` api. * * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API * * @since 1.0.0 * @category layers */ export const layerStorage: ( evaluate: LazyArg ) => Layer.Layer = internal.layerStorage