@midsummer-ai/sdk 0.1.0-staging.3710 → 0.1.0-staging.3716

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.
@@ -114,13 +114,19 @@ async function keyToken(api, key, fresh = false) {
114
114
  }
115
115
  const isRefusal = (value) => !!value && typeof value === "object" && !Array.isArray(value) && value.ok === false;
116
116
  /**
117
- * Whether the database refused a call because it could not read its rows as of the moment the call reads at: it is
118
- * rebuilding what it keeps after a restart, and says `reads below lsn <n> are no longer kept` in the refusal's error
119
- * (or, once it codes it, `history_unavailable`). It clears within seconds, so a read refused so is tried again.
117
+ * Whether the database refused a call for now: `unavailable` (or `history_unavailable`) means it could not finish the
118
+ * call at this moment, as while it catches up after a restart, and clears within seconds, so a read refused so is
119
+ * tried again. The engine's code decides this, never its message.
120
+ */
121
+ const unavailable = (answer) => ["unavailable", "history_unavailable"].includes(answer.why ?? answer.err ?? "");
122
+ /**
123
+ * Whether that refusal was the database rebuilding what it keeps after a restart, which it says as
124
+ * `reads below lsn <n> are no longer kept` (or, once it codes it, `history_unavailable`): such a refusal is
125
+ * reported as `history_unavailable`, with its docs.
120
126
  */
121
127
  const HISTORY_GONE = /reads below lsn \d+ are no longer kept/u;
122
- const historyGone = (answer) => (answer.why ?? answer.err) === "history_unavailable" || (answer.why ?? answer.err) === "unavailable" && HISTORY_GONE.test(answer.error ?? "");
123
- /** How long a read refused `history_unavailable` waits before each try again: 3 seconds in all. */
128
+ const historyGone = (answer) => (answer.why ?? answer.err) === "history_unavailable" || unavailable(answer) && HISTORY_GONE.test(answer.error ?? "");
129
+ /** How long a read refused `unavailable` waits before each try again: 3 seconds in all. */
124
130
  const HISTORY_RETRY_MS = [
125
131
  100,
126
132
  200,
@@ -143,13 +149,13 @@ const caught = (error) => error?.answer ?? {
143
149
  error: error?.message
144
150
  };
145
151
  /**
146
- * A read's value, or its refusal as an `Answer`, tried again while the database refuses it `history_unavailable`,
147
- * at the waits of `HISTORY_RETRY_MS`. Only reads come here: a mutation or an action refused so is thrown at once.
152
+ * A read's value, or its refusal as an `Answer`, tried again while the database refuses it `unavailable`, at the
153
+ * waits of `HISTORY_RETRY_MS`. Only reads come here: a mutation or an action refused so is thrown at once.
148
154
  */
149
155
  async function readAgain(read) {
150
156
  let value = await read().catch(caught);
151
157
  for (const wait of HISTORY_RETRY_MS) {
152
- if (!isRefusal(value) || !historyGone(value)) return value;
158
+ if (!isRefusal(value) || !unavailable(value)) return value;
153
159
  await new Promise((resolve) => setTimeout(resolve, wait));
154
160
  value = await read().catch(caught);
155
161
  }
@@ -351,7 +357,7 @@ async function opened(url, token, refresh, server, key) {
351
357
  return;
352
358
  }
353
359
  const held = item?.ok === false ? item : meta?.error;
354
- if (held && !historyGone(held)) {
360
+ if (held && !unavailable(held)) {
355
361
  tell({ error: refusal(held) });
356
362
  return;
357
363
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midsummer-ai/sdk",
3
- "version": "0.1.0-staging.3710",
3
+ "version": "0.1.0-staging.3716",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Midsummer's handles for an app's code: its Database, Storage, Queues, Vector DB, AI, Email and Agents, with stand-ins for tests.",