ConnectedStorage

Overview

One object for every kind of storage. Data is read and written through run(); a computer gets two extras its own files and its own shells.

run() everywherefiles and terminals on a computer only
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

This is what api.storage.create(), connect(), device(), get() and list() all hand back. You never construct one. The reason it is a single type is the point of the whole resource: the code that reads a database we host is the code that reads one you connected.

The surface

MemberOnDoes
run(config)every storageReads and writes the data.
filesa computer onlyThat machine's own files.
terminalsa computer onlyShells and servers that outlive an answer.

What it carries

idstring

The identifier. Pass it to storageId anywhere one is asked for.

labelstring

The display name. The account holder can change it, so do not match on it.

typestring

filesystem · phone · browser · database · object. The field to branch on.

providerstring

What is behind it — mongodb, d1, r2, s3, iagenify, machine, browser.

managedBystring

Who operates it.

servicestring|null

nosql · sql · object on an IaGenify Cloud storage. null otherwise.

isDefaultboolean

Whether a save with no target lands here.

machineId · hostnamestring|null

On a computer: which machine.

deviceIdstring|null

On a phone: the identifier its browser keeps.

limitsobject

What the storage tracks of its own space.

lastActivityAt · createdAtstring|null

When it was last used, and when it was registered.

No credential is on this object

What you supplied at connection is used by the server to connect and is never handed back. Nothing here can leak a password by being logged or sent to a page.

Branch on type, not on provider

provider tells you what is behind the storage; type tells you what you can do with it. The second is what your code should test.

for (const storage of await api.storage.list()) {
  switch (storage.type) {
    case "database":
      await storage.run({ action: "collections" });
      break;
    case "object":
      await storage.run({ action: "list" });
      break;
    case "filesystem":
      await storage.files.list();          // this machine's own files
      break;
    case "phone":
    case "browser":
      // Its files are in its browser — reachable from the page, not from here.
      break;
  }
}
for storage in api.storage.list():
    if storage.type == "database":
        storage.run(action="collections")
    elif storage.type == "object":
        storage.run(action="list")
    elif storage.type == "filesystem":
        storage.files.list()          # this machine's own files
    elif storage.type in ("phone", "browser"):
        pass  # Its files are in its browser — reachable from the page, not from here.

A device is a storage that keeps its own bytes

typeIts data livesrun()files
database · objectOn the accountyesno
filesystemOn that machineanswers that it is localyes — on that machine
phone · browserIn that browseranswers that it is localno — see the bridge
files and terminals throw rather than return empty

On anything that is not a computer, reaching for files raises storage_not_local — or storage_is_phone on a phone, which says where the files actually are. Test type first; an empty result would be a lie.

import { IaGenifyError } from "iagenify";

try {
  await storage.files.list();
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "storage_not_local") {
    // Not a computer. Its data is read through run().
  }
}
# In Python, files is None on anything that is not a computer:
# its data is read through run().
if storage.files is None:
    storage.run(action="collections")
else:
    storage.files.list()

The same object, wherever it came from

const ours = await api.storage.create({ service: "nosql", label: "App data" });
const yours = await api.storage.connect({ label: "Prod", type: "database", provider: "mongodb",
  endpoint: { credentials: { uri } } });

// Identical calls, different backends
for (const base of [ours, yours]) {
  await base.run({ action: "count", collection: "events" });
}
ours = api.storage.create(service="nosql", label="App data")
yours = api.storage.connect(label="Prod", type="database", provider="mongodb",
                            endpoint={"credentials": {"uri": uri}})

# Identical calls, different backends
for base in (ours, yours):
    base.run(action="count", collection="events")