Stow
API referenceView source

TypeScript embedded API

Run object operations synchronously inside a loaded WASM host. Import from @chester-hill-solutions/stow-s3/embedded.

Defaults and limits

Setting Value
maxBytes / maxObjects 0 means no configured limit
Backend Memory
Payloads Uint8Array; complete objects are buffered
List cursor Return nextCursor unchanged on the next call

Behavior

  • Create a bucket before writing objects.
  • Check capabilities before conditional writes.
  • ifMatch compares the content ETag; ifNoneMatch: "*" requires absence.
  • Empty conditions are unconditional.
  • headObject returns metadata without body bytes.
  • reset clears stored state.
  • Close the runtime before closing its host.

Errors

  • EmbeddedStowError exposes code and message.
  • Common codes include bucket_not_found, object_not_found, quota_exceeded, precondition_failed, conditional_write_unsupported and closed.
  • A failed precondition preserves the current object.
  • Unknown response versions and malformed responses are rejected.

Example

TypeScript13 lines
import { EmbeddedStow } from "@chester-hill-solutions/stow-s3/embedded";
import { loadNodeWasmHost } from "@chester-hill-solutions/stow-s3/node-wasm";

const host = await loadNodeWasmHost();
const store = EmbeddedStow.open(host);
try {
  store.createBucket("files");
  store.putObject("files", "note.txt", new TextEncoder().encode("hello"));
  const file = store.getObject("files", "note.txt");
} finally {
  store.close();
  await host.close();
}

Symbols

BridgeObject · decodeEmbeddedResponse · EMBEDDED_BINARY_PROTOCOL_VERSION · EMBEDDED_PROTOCOL_VERSION · EmbeddedBinaryResponse · EmbeddedBucket · EmbeddedCapabilities · EmbeddedHost · EmbeddedListOptions · EmbeddedObject · EmbeddedObjectPage · EmbeddedPutOptions · EmbeddedStow · EmbeddedStowError · EmbeddedStowOptions · EmbeddedUsage · fromBridgeObject

BridgeObject

TypeScript3 lines
interface BridgeObject  extends Omit<EmbeddedObject, "data"> {
  data?: string | Uint8Array<ArrayBufferLike> | undefined;
}
Field Type Optional Description
data string | Uint8Array<ArrayBufferLike> | undefined Yes Object bytes. Input ownership and size rules depend on the method.
bucket string No Bucket name. Create it before storing objects.
key string No Object or file key within the selected bucket or project.
size number No Total object or content size in bytes; stream uploads require an exact declaration.
etag string No Content validator returned by the store or provider.
contentType string | undefined Yes MIME content type attached to the object or file.
metadata Record<string, string> | undefined Yes User metadata included in storage and sync comparisons.
lastModified string | undefined Yes

decodeEmbeddedResponse

TypeScript1 line
decodeEmbeddedResponse<T>(parsed: unknown, version: number, payload?: Uint8Array<ArrayBufferLike> | undefined, operation?: unknown): T
Parameter Type Required Default Meaning
parsed unknown Yes —
version number Yes —
payload Uint8Array<ArrayBufferLike> | undefined No —
operation unknown No —

Returns: T.

EMBEDDED_BINARY_PROTOCOL_VERSION

TypeScript1 line
const EMBEDDED_BINARY_PROTOCOL_VERSION: 2;

EMBEDDED_PROTOCOL_VERSION

TypeScript1 line
const EMBEDDED_PROTOCOL_VERSION: 1;

EmbeddedBinaryResponse

TypeScript4 lines
interface EmbeddedBinaryResponse {
  metadata: string;
  data?: Uint8Array<ArrayBufferLike> | undefined;
}
Field Type Optional Description
metadata string No User metadata included in storage and sync comparisons.
data Uint8Array<ArrayBufferLike> | undefined Yes Object bytes. Input ownership and size rules depend on the method.

EmbeddedBucket

TypeScript4 lines
interface EmbeddedBucket {
  name: string;
  creationDate?: string | undefined;
}
Field Type Optional Description
name string No Name identifying this bucket, head, protection or error class.
creationDate string | undefined Yes

EmbeddedCapabilities

TypeScript13 lines
interface EmbeddedCapabilities {
  backend: "memory" | "indexeddb" | "host";
  maxBytes: number;
  maxObjects: number;
  persistent: boolean;
  multipart: boolean;
  upstream: boolean;
  conditionalWrites?: boolean | undefined;
  guardedSaves?: boolean | undefined;
  durableSaveRequests?: boolean | undefined;
  recoveryHolds?: boolean | undefined;
  hostMaintenance?: boolean | undefined;
}
Field Type Optional Description
backend "memory" | "indexeddb" | "host" No Storage implementation selected or reported by this handle.
maxBytes number No Maximum managed object bytes; zero means unlimited.
maxObjects number No Maximum object count; zero means unlimited.
persistent boolean No Whether this backend retains data after the handle closes.
multipart boolean No Whether this handle supports multipart operations.
upstream boolean No Whether this handle can use an upstream provider.
conditionalWrites boolean | undefined Yes Whether atomic ETag write conditions are supported.
guardedSaves boolean | undefined Yes Whether the underlying runtime can compare an observation atomically at publication.
durableSaveRequests boolean | undefined Yes Whether a save request key is retained, so a lost reply can be resolved.
recoveryHolds boolean | undefined Yes Whether an observed object's bytes can be protected from mutation until release.
hostMaintenance boolean | undefined Yes Whether namespace recovery inspection and garbage collection are supported.

EmbeddedHost

TypeScript4 lines
interface EmbeddedHost {
  call(request: string): string;
  callBinary(metadata: string, data?: Uint8Array<ArrayBufferLike> | undefined): EmbeddedBinaryResponse;
}

EmbeddedHost.call

TypeScript1 line
call(request: string): string
Parameter Type Required Default Meaning
request string Yes —

Returns: string.

EmbeddedHost.callBinary

Binary calls preserve caller ownership; returned bytes belong to the caller.

TypeScript1 line
callBinary(metadata: string, data?: Uint8Array<ArrayBufferLike> | undefined): EmbeddedBinaryResponse
Parameter Type Required Default Meaning
metadata string Yes — Serialized binary-bridge request or response metadata.
data Uint8Array<ArrayBufferLike> | undefined No — Object bytes. Input ownership and size rules depend on the method.

Returns: EmbeddedBinaryResponse.

EmbeddedListOptions

TypeScript6 lines
interface EmbeddedListOptions {
  prefix?: string | undefined;
  delimiter?: string | undefined;
  cursor?: string | undefined;
  limit?: number | undefined;
}
Field Type Optional Description
prefix string | undefined Yes Only list keys beginning with this prefix.
delimiter string | undefined Yes Groups keys that share it into commonPrefixes; empty lists every key.
cursor string | undefined Yes Opaque continuation value returned by the previous page.
limit number | undefined Yes Maximum results per page; limits and defaults depend on the listing API.

EmbeddedObject

TypeScript10 lines
interface EmbeddedObject {
  bucket: string;
  key: string;
  data?: Uint8Array<ArrayBufferLike> | undefined;
  size: number;
  etag: string;
  contentType?: string | undefined;
  metadata?: Record<string, string> | undefined;
  lastModified?: string | undefined;
}
Field Type Optional Description
bucket string No Bucket name. Create it before storing objects.
key string No Object or file key within the selected bucket or project.
data Uint8Array<ArrayBufferLike> | undefined Yes Object bytes. Input ownership and size rules depend on the method.
size number No Total object or content size in bytes; stream uploads require an exact declaration.
etag string No Content validator returned by the store or provider.
contentType string | undefined Yes MIME content type attached to the object or file.
metadata Record<string, string> | undefined Yes User metadata included in storage and sync comparisons.
lastModified string | undefined Yes

EmbeddedObjectPage

TypeScript6 lines
interface EmbeddedObjectPage {
  objects: EmbeddedObject[];
  truncated: boolean;
  nextCursor?: string | undefined;
  commonPrefixes?: string[] | undefined;
}
Field Type Optional Description
objects EmbeddedObject[] No Objects returned by the listing or persistence snapshot.
truncated boolean No Whether additional matching objects remain.
nextCursor string | undefined Yes Continuation value for the next page when truncated is true.
commonPrefixes string[] | undefined Yes The delimiter groups this page collapsed, in row order.

EmbeddedPutOptions

TypeScript6 lines
interface EmbeddedPutOptions {
  contentType?: string | undefined;
  metadata?: Record<string, string> | undefined;
  ifMatch?: string | undefined;
  ifNoneMatch?: string | undefined;
}
Field Type Optional Description
contentType string | undefined Yes MIME content type attached to the object or file.
metadata Record<string, string> | undefined Yes User metadata included in storage and sync comparisons.
ifMatch string | undefined Yes Write only when the current content ETag matches; empty means unset.
ifNoneMatch string | undefined Yes Use * to create only when absent; empty means unset.

EmbeddedStow

TypeScript21 lines
class EmbeddedStow {
  static open(host: EmbeddedHost, options?: EmbeddedStowOptions): EmbeddedStow;
  readonly handle: number;
  capabilities(): EmbeddedCapabilities;
  usage(): EmbeddedUsage;
  createBucket(bucket: string): void;
  deleteBucket(bucket: string): void;
  listBuckets(): EmbeddedBucket[];
  putObject(bucket: string, key: string, data: Uint8Array<ArrayBufferLike>, options?: EmbeddedPutOptions): EmbeddedObject;
  getObject(bucket: string, key: string): EmbeddedObject;
  headObject(bucket: string, key: string): EmbeddedObject;
  listObjects(bucket: string, options?: EmbeddedListOptions): EmbeddedObjectPage;
  deleteObject(bucket: string, key: string): void;
  readForSave(bucket: string, key: string): EmbeddedSaveObservation;
  saveObject(bucket: string, key: string, data: Uint8Array<ArrayBufferLike>, options?: EmbeddedSaveOptions): EmbeddedSaveResult;
  resolveSave(bucket: string, key: string, requestKey: string): EmbeddedSaveResult;
  releaseObservation(observationToken: string): void;
  copyObject(sourceBucket: string, sourceKey: string, destinationBucket: string, destinationKey: string): EmbeddedObject;
  reset(): void;
  close(): void;
}
Field Type Optional Description
handle number No Open runtime handle issued by the WASM bridge.

EmbeddedStow.open

Open a handle. Retain it until operations finish, then close it.

TypeScript1 line
open(host: EmbeddedHost, options?: EmbeddedStowOptions): EmbeddedStow
Parameter Type Required Default Meaning
host EmbeddedHost Yes — Bind address; native default is 127.0.0.1.
options EmbeddedStowOptions No {} Configuration for this operation; the parameter type lists the accepted settings.

Returns: EmbeddedStow.

EmbeddedStow.capabilities

Return the operations and limits supported by this handle.

TypeScript1 line
capabilities(): EmbeddedCapabilities

Returns: EmbeddedCapabilities.

EmbeddedStow.usage

Return current storage accounting.

TypeScript1 line
usage(): EmbeddedUsage

Returns: EmbeddedUsage.

EmbeddedStow.createBucket

Create the named bucket before storing objects.

TypeScript1 line
createBucket(bucket: string): void
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.

Returns: void.

EmbeddedStow.deleteBucket

Remove an empty bucket; a nonempty bucket is refused.

TypeScript1 line
deleteBucket(bucket: string): void
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.

Returns: void.

EmbeddedStow.listBuckets

Return the buckets visible to the handle.

TypeScript1 line
listBuckets(): EmbeddedBucket[]

Returns: EmbeddedBucket[].

EmbeddedStow.putObject

Store complete bytes and metadata, subject to write conditions and quotas.

TypeScript1 line
putObject(bucket: string, key: string, data: Uint8Array<ArrayBufferLike>, options?: EmbeddedPutOptions): EmbeddedObject
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
key string Yes — Object or file key within the selected bucket or project.
data Uint8Array<ArrayBufferLike> Yes — Object bytes. Input ownership and size rules depend on the method.
options EmbeddedPutOptions No {} Configuration for this operation; the parameter type lists the accepted settings.

Returns: EmbeddedObject.

EmbeddedStow.getObject

Return complete object bytes and metadata.

TypeScript1 line
getObject(bucket: string, key: string): EmbeddedObject
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
key string Yes — Object or file key within the selected bucket or project.

Returns: EmbeddedObject.

EmbeddedStow.headObject

Return object metadata without reading the body into the result.

TypeScript1 line
headObject(bucket: string, key: string): EmbeddedObject
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
key string Yes — Object or file key within the selected bucket or project.

Returns: EmbeddedObject.

EmbeddedStow.listObjects

Return one page. Pass nextCursor to continue when truncated is true.

TypeScript1 line
listObjects(bucket: string, options?: EmbeddedListOptions): EmbeddedObjectPage
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
options EmbeddedListOptions No {} Configuration for this operation; the parameter type lists the accepted settings.

Returns: EmbeddedObjectPage.

EmbeddedStow.deleteObject

Delete the selected object; deleting a missing object is idempotent.

TypeScript1 line
deleteObject(bucket: string, key: string): void
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
key string Yes — Object or file key within the selected bucket or project.

Returns: void.

EmbeddedStow.readForSave

Observe an object, or its absence, before changing it.

TypeScript1 line
readForSave(bucket: string, key: string): EmbeddedSaveObservation
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
key string Yes — Object or file key within the selected bucket or project.

Returns: EmbeddedSaveObservation.

EmbeddedStow.saveObject

Publish a save that compares at publication, or replaces deliberately.

TypeScript1 line
saveObject(bucket: string, key: string, data: Uint8Array<ArrayBufferLike>, options?: EmbeddedSaveOptions): EmbeddedSaveResult
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
key string Yes — Object or file key within the selected bucket or project.
data Uint8Array<ArrayBufferLike> Yes — Object bytes. Input ownership and size rules depend on the method.
options EmbeddedSaveOptions No {} Configuration for this operation; the parameter type lists the accepted settings.

Returns: EmbeddedSaveResult.

EmbeddedStow.resolveSave

Ask what a request key did, instead of writing again.

TypeScript1 line
resolveSave(bucket: string, key: string, requestKey: string): EmbeddedSaveResult
Parameter Type Required Default Meaning
bucket string Yes — Bucket name. Create it before storing objects.
key string Yes — Object or file key within the selected bucket or project.
requestKey string Yes — Unique persisted request identity for capture or save recovery.

Returns: EmbeddedSaveResult.

EmbeddedStow.releaseObservation

Drop a token this caller will not use, rather than waiting for its expiry.

TypeScript1 line
releaseObservation(observationToken: string): void
Parameter Type Required Default Meaning
observationToken string Yes —

Returns: void.

EmbeddedStow.copyObject

Copy source bytes and metadata to the destination object.

TypeScript1 line
copyObject(sourceBucket: string, sourceKey: string, destinationBucket: string, destinationKey: string): EmbeddedObject
Parameter Type Required Default Meaning
sourceBucket string Yes — Bucket containing the source object.
sourceKey string Yes — Source object key.
destinationBucket string Yes — Bucket that receives the copy.
destinationKey string Yes — Object key that receives the copy.

Returns: EmbeddedObject.

EmbeddedStow.reset

Clear storage state where the backend supports reset.

TypeScript1 line
reset(): void

Returns: void.

EmbeddedStow.close

Release this handle. Do not submit new operations after closing it.

TypeScript1 line
close(): void

Returns: void.

EmbeddedStowError

TypeScript4 lines
class EmbeddedStowError  extends Error {
  readonly code: string;
  constructor(code: string, message: string);
}
Field Type Optional Description
code string No Structured error code; inspect the code rather than matching message text.
name string No Name identifying this bucket, head, protection or error class.
message string No Human-readable error message.
stack string | undefined Yes JavaScript stack trace, when available.
cause unknown Yes Underlying error cause, when provided.

EmbeddedStowError.constructor

function Object() { [native code] }

TypeScript1 line
constructor(code: string, message: string)
Parameter Type Required Default Meaning
code string Yes — Structured error code; inspect the code rather than matching message text.
message string Yes — Human-readable error message.

Returns: EmbeddedStowError.

EmbeddedStowOptions

TypeScript4 lines
interface EmbeddedStowOptions {
  maxBytes?: number | undefined;
  maxObjects?: number | undefined;
}
Field Type Optional Description
maxBytes number | undefined Yes Maximum managed object bytes; zero means unlimited.
maxObjects number | undefined Yes Maximum object count; zero means unlimited.

EmbeddedUsage

TypeScript4 lines
interface EmbeddedUsage {
  bytes: number;
  objects: number;
}
Field Type Optional Description
bytes number No Current managed object payload bytes.
objects number No Objects returned by the listing or persistence snapshot.

fromBridgeObject

TypeScript1 line
fromBridgeObject(object: BridgeObject): EmbeddedObject
Parameter Type Required Default Meaning
object BridgeObject Yes —

Returns: EmbeddedObject.