Storage API
configureStorage Configure
Optionally configures Local and Session before the first Storage operation.
Signature
export function configureStorage(options: StorageConfiguration = {}): void;Example
import { configureStorage } from "@fast-china/utils";
configureStorage({ prefix: "admin:", crypto: false });Input
| Input | Type | Required / default | Description |
|---|---|---|---|
options | StorageConfiguration | Optional; 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
export function isStorageConfigured(): boolean;Example
import { isStorageConfigured } from "@fast-china/utils";
const result = isStorageConfigured();Input: No parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | True after explicit configuration or implicit activation. |
Local.get / Session.get Read
Reads and decodes a namespaced business value; expired records are removed.
Signature
get<Value = string>(key: string, options?: StorageReadOptions): Value | undefined;Example
import { Local } from "@fast-china/utils";
const result = Local.get<{ name: string }>("profile");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
key | string | Required | Nonempty business key without the global prefix. |
options | StorageReadOptions | Optional | Per-call Base64 codec override; must match the codec used for writing. |
Returns
| Value | Type | Description |
|---|---|---|
result | Value | undefined | Decoded business value, or undefined when missing or expired. |
Local.set / Session.set Write
Encodes and writes a business value with an optional TTL.
Signature
set<Value>(key: string, value: Value, options?: StorageWriteOptions): void;Example
import { Local } from "@fast-china/utils";
Local.set("profile", { name: "Fast" }, { ttlMs: 3_600_000 });Input
| Input | Type | Required / default | Description |
|---|---|---|---|
key | string | Required | Nonempty business key without the global prefix. |
value | Value | Required | Business value serializable by the current codec. |
options | StorageWriteOptions | Optional | Per-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
has(key: string): boolean;Example
import { Local } from "@fast-china/utils";
const result = Local.has("profile");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
key | string | Required | Nonempty business key without the global prefix. |
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when the key exists and its envelope is valid. |
Local.keys / Session.keys Keys
Lists business keys in the current namespace.
Signature
keys(): string[];Example
import { Local } from "@fast-china/utils";
const result = Local.keys();Input: No parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | string[] | New lexically sorted array with physical prefixes removed. |
Local.remove / Session.remove Remove
Idempotently removes one business key.
Signature
remove(key: string): void;Example
import { Local } from "@fast-china/utils";
Local.remove("profile");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
key | string | Required | Nonempty 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
removeByPrefix(keyPrefix: string): void;Example
import { Local } from "@fast-china/utils";
Local.removeByPrefix("profile:");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
keyPrefix | string | Required | Nonempty 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
pruneExpired(): number;Example
import { Local } from "@fast-china/utils";
const result = Local.pruneExpired();Input: No parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | number | Number of records actually removed. |
Local.clear / Session.clear Clear
Clears the current namespace without affecting other application keys on the same backend.
Signature
clear(): void;Example
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.
