Skip to content

Storage API ​

configureStorage Configure ​

Optionally configures Local and Session before the first Storage operation.

Signature ​

ts
export function configureStorage(options: StorageConfiguration = {}): void;

Example ​

ts
import { configureStorage } from "@fast-china/utils";

configureStorage({ prefix: "admin:", crypto: false });

Input ​

InputTypeRequired / defaultDescription
optionsStorageConfigurationOptional; defaults to {}Optional global key prefix, codec, Base64 obfuscation options, and clock.

Returns: void.

isStorageConfigured Configure ​

Reports whether global Storage is active, through explicit configuration or the first Storage operation.

Signature ​

ts
export function isStorageConfigured(): boolean;

Example ​

ts
import { isStorageConfigured } from "@fast-china/utils";

const result = isStorageConfigured();

Input: No parameters.

Returns ​

ValueTypeDescription
resultbooleanTrue after explicit configuration or implicit activation.

Local.get / Session.get Read ​

Reads and decodes a namespaced business value; expired records are removed.

Signature ​

ts
get<Value = string>(key: string, options?: StorageReadOptions): Value | undefined;

Example ​

ts
import { Local } from "@fast-china/utils";

const result = Local.get<{ name: string }>("profile");

Input ​

InputTypeRequired / defaultDescription
keystringRequiredNonempty business key without the global prefix.
optionsStorageReadOptionsOptionalPer-call Base64 codec override; must match the codec used for writing.

Returns ​

ValueTypeDescription
resultValue | undefinedDecoded business value, or undefined when missing or expired.

Local.set / Session.set Write ​

Encodes and writes a business value with an optional TTL.

Signature ​

ts
set<Value>(key: string, value: Value, options?: StorageWriteOptions): void;

Example ​

ts
import { Local } from "@fast-china/utils";

Local.set("profile", { name: "Fast" }, { ttlMs: 3_600_000 });

Input ​

InputTypeRequired / defaultDescription
keystringRequiredNonempty business key without the global prefix.
valueValueRequiredBusiness value serializable by the current codec.
optionsStorageWriteOptionsOptionalPer-call codec and lifetime in milliseconds.

Returns: void. invalid keys, TTLs, values, or backend failures throw.

Local.has / Session.has Exists ​

Checks key existence, expiry and the stored envelope without decoding the value.

Signature ​

ts
has(key: string): boolean;

Example ​

ts
import { Local } from "@fast-china/utils";

const result = Local.has("profile");

Input ​

InputTypeRequired / defaultDescription
keystringRequiredNonempty business key without the global prefix.

Returns ​

ValueTypeDescription
resultbooleantrue when the key exists and its envelope is valid.

Local.keys / Session.keys Keys ​

Lists business keys in the current namespace.

Signature ​

ts
keys(): string[];

Example ​

ts
import { Local } from "@fast-china/utils";

const result = Local.keys();

Input: No parameters.

Returns ​

ValueTypeDescription
resultstring[]New lexically sorted array with physical prefixes removed.

Local.remove / Session.remove Remove ​

Idempotently removes one business key.

Signature ​

ts
remove(key: string): void;

Example ​

ts
import { Local } from "@fast-china/utils";

Local.remove("profile");

Input ​

InputTypeRequired / defaultDescription
keystringRequiredNonempty business key without the global prefix.

Returns: void.

Local.removeByPrefix / Session.removeByPrefix Remove ​

Removes all business keys starting with the given text in the current namespace.

Signature ​

ts
removeByPrefix(keyPrefix: string): void;

Example ​

ts
import { Local } from "@fast-china/utils";

Local.removeByPrefix("profile:");

Input ​

InputTypeRequired / defaultDescription
keyPrefixstringRequiredNonempty business-key prefix excluding the global prefix.

Returns: void. keys outside the namespace are unaffected.

Local.pruneExpired / Session.pruneExpired Prune ​

Scans and removes all expired records in the current namespace.

Signature ​

ts
pruneExpired(): number;

Example ​

ts
import { Local } from "@fast-china/utils";

const result = Local.pruneExpired();

Input: No parameters.

Returns ​

ValueTypeDescription
resultnumberNumber of records actually removed.

Local.clear / Session.clear Clear ​

Clears the current namespace without affecting other application keys on the same backend.

Signature ​

ts
clear(): void;

Example ​

ts
import { Session } from "@fast-china/utils";

Session.clear();

Input: No parameters.

Returns: void.

Shared behavior and boundaries ​

Call configureStorage before the first Storage operation. The defaults use the fast__ prefix and JSON codec. Once active, equivalent configuration is idempotent and conflicting configuration throws. A get generic affects static types only; it does not validate or convert business values. Per-operation crypto options must match on writes and reads; the envelope does not store the codec. Base64 obfuscation does not protect sensitive data. Reading an expired entry may remove it. clear is prefix-scoped. uni-app has no Session backend, and Session operations throw. has checks existence, expiry and the stored envelope without decoding the value. isStorageConfigured returns true after either explicit or implicit activation. Quota, privacy-policy, invalid-JSON and unavailable-backend failures propagate from the relevant operation; they are not cache misses.