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
| Member | On | Does |
|---|---|---|
| run(config) | every storage | Reads and writes the data. |
| files | a computer only | That machine's own files. |
| terminals | a computer only | Shells and servers that outlive an answer. |
What it carries
idstringThe identifier. Pass it to storageId anywhere one is asked for.
labelstringThe display name. The account holder can change it, so do not match on it.
typestringfilesystem · phone · browser · database · object. The field to branch on.
providerstringWhat is behind it — mongodb, d1, r2, s3, iagenify, machine, browser.
managedBystringWho operates it.
servicestring|nullnosql · sql · object on an IaGenify Cloud storage. null otherwise.
isDefaultbooleanWhether a save with no target lands here.
machineId · hostnamestring|nullOn a computer: which machine.
deviceIdstring|nullOn a phone: the identifier its browser keeps.
limitsobjectWhat the storage tracks of its own space.
lastActivityAt · createdAtstring|nullWhen it was last used, and when it was registered.
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
| type | Its data lives | run() | files |
|---|---|---|---|
| database · object | On the account | yes | no |
| filesystem | On that machine | answers that it is local | yes — on that machine |
| phone · browser | In that browser | answers that it is local | no — see the bridge |
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")