stratus-db 0.4.0 → 0.5.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 CHANGED
@@ -66,6 +66,14 @@ Gateway's 403 Forbidden for a brand-new key, which works within a minute or two
66
66
  - Keys (with a key reaching every database): `listKeys()`, `createKey({name, scope})`,
67
67
  `revokeKey(keyId)`.
68
68
  - Codec: `encode`, `decode` (typed-JSON text), `toJSONValue`, `fromJSONValue`.
69
+ - `rowId(n)`: a row named by its row id.
70
+
71
+ **Keys and row ids.** A primary key is a UUID (`squuid()`), a string or an integer (a long:
72
+ past 2^53, pass a `BigInt`). Every row also carries `"stratus/id"`, a row id the database assigns
73
+ when the row is made. `transact` answers `{ t, pks, ids }`. Where a key goes - `pull`, `delete`,
74
+ a row's key attribute - `rowId(n)` names a row by its id; a bare integer is always a primary key.
75
+ Queries return rows in row id order (the order they were made), `{ order: "desc" }` newest first;
76
+ `next` is a row id.
69
77
 
70
78
  Queries: docs/query.md ("JSON"). Requests go to `<url>/v1/dbs/<id>/...` with `Authorization:
71
79
  Bearer <apiKey>`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stratus-db",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "The stratus-db service from JavaScript: typed JSON over fetch, no dependencies.",
5
5
  "homepage": "https://stratus-db.com",
6
6
  "license": "Apache-2.0",
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.4.0";
18
+ export const VERSION = "0.5.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;
@@ -269,6 +269,13 @@ export const localDate = (text) => LocalDate.parse(text);
269
269
  export const double = (v) => new Double(v);
270
270
  export const list = (...items) => List.from(items);
271
271
 
272
+ /**
273
+ * A row id, tagged: { "stratus/id": n }. Every row carries its row id (row["stratus/id"]), a
274
+ * long the database assigns when the row is made; a command or a pull names a row by it where a
275
+ * bare integer would be a primary key.
276
+ */
277
+ export const rowId = (n) => ({ "stratus/id": n });
278
+
272
279
  // ------------------------------------------------------------------ Typed JSON
273
280
  // Typed JSON (docs/json.md): stratus's encoding, MongoDB Extended JSON v2's tags where they
274
281
  // mean the same and stratus's own where it has none. encode/decode work on JSON text;
@@ -673,9 +680,11 @@ export class Client {
673
680
  }
674
681
 
675
682
  /**
676
- * Transacts: { t, pks, duplicate? }. tx: rows (each with its primary key: squuid()),
677
- * retract: rows of attributes to remove, delete: primary keys, txId: makes a retry safe,
678
- * match: rows whose attributes must hold those values now (else a 409 "conflict").
683
+ * Transacts: { t, pks, ids, duplicate? } - pks and ids are tx's rows' primary keys and row ids,
684
+ * in order. tx: rows (each with its primary key: squuid(); or naming its row by rowId(n) in
685
+ * the key's place), retract: rows of attributes to remove, delete: primary keys (or rowId(n)),
686
+ * txId: makes a retry safe, match: rows whose attributes must hold those values now (else a
687
+ * 409 "conflict").
679
688
  */
680
689
  async transact(id, { tx, retract, delete: del, txId, match }) {
681
690
  const body = {};
@@ -687,7 +696,11 @@ export class Client {
687
696
  return Client.ok(await this.callDb(id, "POST", "/transact", body));
688
697
  }
689
698
 
690
- /** One page of query q (docs/query.md, "JSON"): { rows, next, t }. */
699
+ /**
700
+ * One page of query q (docs/query.md, "JSON"): { rows, next, t } - rows in row id order (the
701
+ * order they were made; { order: "desc" }: newest first), next the cursor (a row id) to pass
702
+ * as after.
703
+ */
691
704
  async query(id, q = {}) {
692
705
  const { asOf, ...rest } = q;
693
706
  return Client.ok(await this.callDb(id, "POST", "/query", asOf === undefined ? rest : { ...rest, "as-of": asOf }));
@@ -705,8 +718,8 @@ export class Client {
705
718
  }
706
719
 
707
720
  /**
708
- * The rows of primary keys pks, in order (null where there is none); { asOf: t } reads them as
709
- * they stood after transaction t.
721
+ * The rows of pks (primary keys, or rowId(n)), in order (null where there is none); { asOf: t }
722
+ * reads them as they stood after transaction t.
710
723
  */
711
724
  async pull(id, pks, { asOf } = {}) {
712
725
  return (Client.ok(await this.callDb(id, "POST", "/pull", asOf === undefined ? { pks } : { pks, "as-of": asOf }))).rows;