Skip to content

@jayoncode/storage API


@jayoncode/storage API ​

Classes ​

StorageError ​

Extends ​

  • Error

Extended by ​

Constructors ​

Constructor ​
ts
new StorageError(
   message: string, 
   code: StorageErrorCode, 
   options?: StorageErrorOptions): StorageError;
Parameters ​
ParameterType
messagestring
codeStorageErrorCode
optionsStorageErrorOptions
Returns ​

StorageError

Overrides ​
ts
Error.constructor

Properties ​

PropertyModifierType
codereadonlyStorageErrorCode
detailsreadonlyReadonly<PlainObject> | undefined

ConfigurationError ​

Extends ​

Constructors ​

Constructor ​
ts
new ConfigurationError(message: string, options?: StorageErrorOptions): ConfigurationError;
Parameters ​
ParameterType
messagestring
optionsStorageErrorOptions
Returns ​

ConfigurationError

Overrides ​

StorageError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyStorageErrorCodeStorageError.code
detailsreadonlyReadonly<PlainObject> | undefinedStorageError.details

SerializationError ​

Extends ​

Constructors ​

Constructor ​
ts
new SerializationError(message: string, options?: StorageErrorOptions): SerializationError;
Parameters ​
ParameterType
messagestring
optionsStorageErrorOptions
Returns ​

SerializationError

Overrides ​

StorageError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyStorageErrorCodeStorageError.code
detailsreadonlyReadonly<PlainObject> | undefinedStorageError.details

QuotaExceededError ​

Extends ​

Constructors ​

Constructor ​
ts
new QuotaExceededError(message: string, options?: StorageErrorOptions): QuotaExceededError;
Parameters ​
ParameterType
messagestring
optionsStorageErrorOptions
Returns ​

QuotaExceededError

Overrides ​

StorageError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyStorageErrorCodeStorageError.code
detailsreadonlyReadonly<PlainObject> | undefinedStorageError.details

MigrationError ​

Extends ​

Constructors ​

Constructor ​
ts
new MigrationError(message: string, options?: StorageErrorOptions): MigrationError;
Parameters ​
ParameterType
messagestring
optionsStorageErrorOptions
Returns ​

MigrationError

Overrides ​

StorageError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyStorageErrorCodeStorageError.code
detailsreadonlyReadonly<PlainObject> | undefinedStorageError.details

AdapterError ​

Extends ​

Constructors ​

Constructor ​
ts
new AdapterError(message: string, options?: StorageErrorOptions): AdapterError;
Parameters ​
ParameterType
messagestring
optionsStorageErrorOptions
Returns ​

AdapterError

Overrides ​

StorageError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyStorageErrorCodeStorageError.code
detailsreadonlyReadonly<PlainObject> | undefinedStorageError.details

Interfaces ​

StorageErrorOptions ​

Properties ​

PropertyModifierType
cause?readonlyunknown
details?readonlyPlainObject

TtlDuration ​

Duration for TTL policies — convert to milliseconds at write time.

Properties ​

PropertyModifierType
milliseconds?readonlynumber
seconds?readonlynumber
minutes?readonlynumber
hours?readonlynumber
days?readonlynumber

StoragePolicy ​

Named write preset — v1 honors ttl only.

Properties ​

PropertyModifierType
ttl?readonlyTtlDuration

StorageAdapter ​

Sync string key/value backend (browser Storage-compatible).

Methods ​

getItem() ​
ts
getItem(key: string): string | null;
Parameters ​
ParameterType
keystring
Returns ​

string | null

setItem() ​
ts
setItem(key: string, value: string): void;
Parameters ​
ParameterType
keystring
valuestring
Returns ​

void

removeItem() ​
ts
removeItem(key: string): void;
Parameters ​
ParameterType
keystring
Returns ​

void

keys()? ​
ts
optional keys(): readonly string[];

Optional: list all keys (required for namespace clear).

Returns ​

readonly string[]


StorageEnvelopeV1 ​

Type Parameters ​

Type ParameterDefault type
Tunknown

Properties ​

PropertyModifierType
vreadonly1
schemaVersionreadonlystring
savedAtreadonlynumber
expiresAt?readonlynumber
valuereadonlyT

CreateStorageOptions ​

Type Parameters ​

Type ParameterDefault type
Tunknown

Properties ​

PropertyModifierTypeDescription
namespacereadonlystring-
adapterreadonlyStorageAdapter-
ttl?readonlyTtlDurationDefault TTL when set omits per-write TTL and policy TTL.
policies?readonlyReadonly<Record<string, StoragePolicy>>Named write presets (copied into an instance-local map).
schemaVersion?readonlystringApp schema id stored on envelopes (default "1").
serialize?readonly(value: unknown) => string-
deserialize?readonly(raw: string) => unknown-
migrate?readonly(envelope: StorageEnvelope<T>, fromVersion: string) => StorageEnvelope<T> | nullCalled when a loaded envelope's schemaVersion differs from the configured version. Return the migrated envelope, or null to drop the entry.

SetStorageOptions ​

Properties ​

PropertyModifierTypeDescription
ttl?readonlyTtlDuration-
policy?readonlystringNamed policy from policies / definePolicy (validated even when ttl overrides).

JayOnCodeStorage ​

Type Parameters ​

Type ParameterDefault type
Tunknown

Properties ​

PropertyModifierType
namespacereadonlystring
schemaVersionreadonlystring

Methods ​

get() ​
ts
get(key: string): T | null;
Parameters ​
ParameterType
keystring
Returns ​

T | null

set() ​
ts
set(
   key: string, 
   value: T, 
   options?: SetStorageOptions): void;
Parameters ​
ParameterType
keystring
valueT
options?SetStorageOptions
Returns ​

void

remove() ​
ts
remove(key: string): void;
Parameters ​
ParameterType
keystring
Returns ​

void

has() ​
ts
has(key: string): boolean;

Whether a non-expired envelope exists. Does not migrate or persist — call get to upgrade schemaVersion.

Parameters ​
ParameterType
keystring
Returns ​

boolean

clear() ​
ts
clear(): void;

Remove all keys in this namespace. Requires adapter.keys(); throws ConfigurationError if missing.

Returns ​

void

peek() ​
ts
peek(key: string): StorageEnvelope<T> | null;

Read the envelope without applying migration (still drops expired).

Parameters ​
ParameterType
keystring
Returns ​

StorageEnvelope<T> | null

definePolicy() ​
ts
definePolicy(name: string, policy: StoragePolicy): void;

Register or replace a named write preset (ttl-only in v1).

Parameters ​
ParameterType
namestring
policyStoragePolicy
Returns ​

void

Type Aliases ​

StorageErrorCode ​

ts
type StorageErrorCode = 
  | "configuration_error"
  | "serialization_error"
  | "quota_exceeded"
  | "migration_error"
  | "adapter_error";

StorageEnvelope ​

ts
type StorageEnvelope<T> = StorageEnvelopeV1<T>;

Type Parameters ​

Type ParameterDefault type
Tunknown

Variables ​

packageId ​

ts
const packageId: "storage" = "storage";

Stable package id for scaffolding / playground demos.

Functions ​

createMemoryAdapter() ​

ts
function createMemoryAdapter(): StorageAdapter;

In-memory adapter backed by a Map. Use for tests, SSR, and ephemeral data.

Import from the package root (not a repo file path):

ts
import { createMemoryAdapter } from "@jayoncode/storage";

Returns ​

StorageAdapter


createLocalStorageAdapter() ​

ts
function createLocalStorageAdapter(): StorageAdapter;

Explicit localStorage adapter — values survive reload in the browser.

ts
import { createLocalStorageAdapter } from "@jayoncode/storage";

Returns ​

StorageAdapter


createSessionStorageAdapter() ​

ts
function createSessionStorageAdapter(): StorageAdapter;

Explicit sessionStorage adapter — values last for the tab session.

ts
import { createSessionStorageAdapter } from "@jayoncode/storage";

Returns ​

StorageAdapter


createStorage() ​

ts
function createStorage<T>(options: CreateStorageOptions<T>): JayOnCodeStorage<T>;

Type Parameters ​

Type ParameterDefault type
Tunknown

Parameters ​

ParameterType
optionsCreateStorageOptions<T>

Returns ​

JayOnCodeStorage<T>


defaultSerialize() ​

ts
function defaultSerialize(value: unknown): string;

Parameters ​

ParameterType
valueunknown

Returns ​

string


defaultDeserialize() ​

ts
function defaultDeserialize(raw: string): unknown;

Parameters ​

ParameterType
rawstring

Returns ​

unknown


isQuotaExceededError() ​

ts
function isQuotaExceededError(error: unknown): boolean;

Parameters ​

ParameterType
errorunknown

Returns ​

boolean

An ecosystem of independent, headless TypeScript libraries engineered for modern web development. Every package includes interactive playgrounds and documentation that evolves alongside the code.