stratus-db 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +1 -1
- package/stratus-db.js +23 -6
package/README.md
CHANGED
|
@@ -57,7 +57,8 @@ Gateway's 403 Forbidden for a brand-new key, which works within a minute or two
|
|
|
57
57
|
- Catalog: `listDbs({deleted})`, `dbByName(name)`, `dbRecord(id)`, `createDb({name, primaryKey})`,
|
|
58
58
|
`renameDb(id, name)`, `deleteDb(id)`.
|
|
59
59
|
- A database: `status(id)`, `transact(id, {tx, retract, delete, txId, match})`, `query(id, q)`,
|
|
60
|
-
`queryAll(id, q)` (async iterator), `pull(id, pks, {asOf})` (and `asOf: t` in a query: the database as it stood after t), `requestIndex(id, att)
|
|
60
|
+
`queryAll(id, q)` (async iterator), `pull(id, pks, {asOf})` (and `asOf: t` in a query: the database as it stood after t), `requestIndex(id, att, {required})` (att an attribute, or an array of 2 to 8 for a
|
|
61
|
+
multi-attribute index: queried by tuples, `["=", ["a", "b"], [x, y]]`; docs/query.md),
|
|
61
62
|
`awaitIndex(id, att)`, `dropIndex(id, att)`, `history(id, {from, limit})`, `historyAll`,
|
|
62
63
|
`fork(id, {t, name})` (a new database, this one as of t), `excise(id, {rows,
|
|
63
64
|
attributes})` (erasure: rows and {pk, att} out of the state, indexes, history and forks),
|
package/package.json
CHANGED
package/stratus-db.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// "Authorization: Bearer <key>".
|
|
16
16
|
|
|
17
17
|
/** The client's version: package.json's, which release-js.yml checks against it. */
|
|
18
|
-
export const VERSION = "0.
|
|
18
|
+
export const VERSION = "0.4.0";
|
|
19
19
|
|
|
20
20
|
const USER_AGENT = `stratus-db-js/${VERSION}`;
|
|
21
21
|
const IN_NODE = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
@@ -529,6 +529,15 @@ function queryString(params) {
|
|
|
529
529
|
|
|
530
530
|
function attName(att) { return att instanceof Keyword ? att.fullName : String(att).replace(/^:/, ""); }
|
|
531
531
|
|
|
532
|
+
// An index's name: an attribute's, or a multi-attribute index's (an array) joined by commas -
|
|
533
|
+
// how the status keys it, and the DELETE path names it.
|
|
534
|
+
function indexName(att) { return Array.isArray(att) ? att.map(attName).join(",") : attName(att); }
|
|
535
|
+
|
|
536
|
+
// The DELETE path of an index: each name's parts encoded, its slashes and commas kept.
|
|
537
|
+
function indexPath(att) {
|
|
538
|
+
return indexName(att).split(",").map((n) => n.split("/").map(encodeURIComponent).join("/")).join(",");
|
|
539
|
+
}
|
|
540
|
+
|
|
532
541
|
/** A client of the stratus service at opts.url (see the module's comment for opts). */
|
|
533
542
|
export function connect(opts) {
|
|
534
543
|
return new Client(opts);
|
|
@@ -703,18 +712,26 @@ export class Client {
|
|
|
703
712
|
return (Client.ok(await this.callDb(id, "POST", "/pull", asOf === undefined ? { pks } : { pks, "as-of": asOf }))).rows;
|
|
704
713
|
}
|
|
705
714
|
|
|
706
|
-
/**
|
|
707
|
-
|
|
708
|
-
|
|
715
|
+
/**
|
|
716
|
+
* Requests a value index on att: { att, state } ("building" until a checkpoint builds it).
|
|
717
|
+
* att is an attribute, or an array of 2 to 8 for a multi-attribute index (its rows keyed by
|
|
718
|
+
* the tuple of their values; queried by tuple predicates), with { required }: the attributes
|
|
719
|
+
* a row needs a value of to be in it.
|
|
720
|
+
*/
|
|
721
|
+
async requestIndex(id, att, { required } = {}) {
|
|
722
|
+
const body = { att: Array.isArray(att) ? att.map(attName) : attName(att) };
|
|
723
|
+
if (required !== undefined) body.required = required.map(attName);
|
|
724
|
+
return Client.ok(await this.callDb(id, "POST", "/indexes", body));
|
|
709
725
|
}
|
|
710
726
|
|
|
727
|
+
/** Drops att's index (an attribute, or a multi-attribute index's array). */
|
|
711
728
|
async dropIndex(id, att) {
|
|
712
|
-
return Client.ok(await this.callDb(id, "DELETE", `/indexes/${
|
|
729
|
+
return Client.ok(await this.callDb(id, "DELETE", `/indexes/${indexPath(att)}`));
|
|
713
730
|
}
|
|
714
731
|
|
|
715
732
|
/** Waits until att's index is ready (rejects if it failed, or after timeoutMs). */
|
|
716
733
|
async awaitIndex(id, att, { timeoutMs = 60000, intervalMs = 200 } = {}) {
|
|
717
|
-
const name =
|
|
734
|
+
const name = indexName(att);
|
|
718
735
|
const deadline = Date.now() + timeoutMs;
|
|
719
736
|
for (;;) {
|
|
720
737
|
const s = await this.status(id);
|