@midsummer-ai/sdk 0.1.0-staging.3796 → 0.1.0-staging.3802

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.
@@ -1,6 +1,6 @@
1
- import { n as AuthStore } from "../store-CRqU5WCe.mjs";
1
+ import { n as AuthStore } from "../store-F6n7TyY9.mjs";
2
2
  import { SignInMail } from "./mail.mjs";
3
- import { a as Auth } from "../index-C0ykY_s9.mjs";
3
+ import { a as Auth } from "../index-DDYlYmhT.mjs";
4
4
  //#region src/auth/contract.d.ts
5
5
  interface AuthHarness {
6
6
  /** Sign-in over a store with no users, made with `scopes: CONTRACT_SCOPES`. */
package/auth/contract.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as LIMITS, l as LIMIT_WINDOW_MS, r as AuthError, u as SETTINGS_TTL_MS } from "../auth-BoKoF1zJ.mjs";
1
+ import { c as LIMITS, l as LIMIT_WINDOW_MS, r as AuthError, u as SETTINGS_TTL_MS } from "../auth-C5lH_TF0.mjs";
2
2
  import { IMPERSONATION_TOKEN_MS, startImpersonation } from "./impersonate.mjs";
3
3
  //#region src/auth/contract.ts
4
4
  /**
package/auth/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { n as AuthStore, r as databaseStore, t as AuthCall } from "../store-CRqU5WCe.mjs";
1
+ import { n as AuthStore, r as databaseStore, t as AuthCall } from "../store-F6n7TyY9.mjs";
2
2
  import { i as SignUpPolicy, n as CaptchaProvider, r as PublicSettings, t as AuthSettings } from "../settings-Dz3irtlu.mjs";
3
3
  import { SignInMail, SignInMailKind, checkSignInMail, signInWords } from "./mail.mjs";
4
- import { _ as AuthEvent, a as Auth, b as EventSend, c as AuthOptions, d as IMPERSONATION_S, f as SESSION_CACHE_S, g as createAuth, h as auth, i as AgentKey, l as AuthUser, m as SignedInAgent, n as AUTH_ROUTES, o as AuthError, p as SignedIn, r as AgentGrant, s as AuthErrorCode, t as AUTH_PATH, u as AuthUserRecord, v as AuthEventBatch, y as AuthEventType } from "../index-C0ykY_s9.mjs";
4
+ import { _ as AuthEvent, a as Auth, b as EventSend, c as AuthOptions, d as IMPERSONATION_S, f as SESSION_CACHE_S, g as createAuth, h as auth, i as AgentKey, l as AuthUser, m as SignedInAgent, n as AUTH_ROUTES, o as AuthError, p as SignedIn, r as AgentGrant, s as AuthErrorCode, t as AUTH_PATH, u as AuthUserRecord, v as AuthEventBatch, y as AuthEventType } from "../index-DDYlYmhT.mjs";
5
5
  import { i as authFiles } from "../files-B553U-d6.mjs";
6
6
  export { AUTH_PATH, AUTH_ROUTES, AgentGrant, AgentKey, Auth, type AuthCall, AuthError, AuthErrorCode, type AuthEvent, type AuthEventBatch, type AuthEventType, AuthOptions, type AuthSettings, type AuthStore, AuthUser, AuthUserRecord, type CaptchaProvider, type EventSend, IMPERSONATION_S, type PublicSettings, SESSION_CACHE_S, type SignInMail, type SignInMailKind, type SignUpPolicy, SignedIn, SignedInAgent, auth, authFiles, checkSignInMail, createAuth, databaseStore, signInWords };
package/auth/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as SESSION_CACHE_S, d as databaseStore, i as IMPERSONATION_S, n as AUTH_ROUTES, o as auth, r as AuthError, s as createAuth, t as AUTH_PATH } from "../auth-BoKoF1zJ.mjs";
1
+ import { a as SESSION_CACHE_S, d as databaseStore, i as IMPERSONATION_S, n as AUTH_ROUTES, o as auth, r as AuthError, s as createAuth, t as AUTH_PATH } from "../auth-C5lH_TF0.mjs";
2
2
  import { checkSignInMail, signInWords } from "./mail.mjs";
3
3
  import { n as authFiles } from "../files-DhPeWwcT.mjs";
4
4
  export { AUTH_PATH, AUTH_ROUTES, AuthError, IMPERSONATION_S, SESSION_CACHE_S, auth, authFiles, checkSignInMail, createAuth, databaseStore, signInWords };
package/auth/react.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-cU04Dzrt.mjs";
1
+ import { t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-DD0xZprk.mjs";
2
2
  import { DatabaseProvider } from "../database/react.mjs";
3
3
  import { a as WORDS, c as deviceOf, i as CAPTCHA_WIDGETS, l as screenName, n as textOn, o as ago, t as authCss, u as setupKeyOf } from "../style-CCFT-5rG.mjs";
4
4
  import { a as shapeAttributes, r as ICONS, t as qrPath } from "../qr-BySxqLW6.mjs";
@@ -1,4 +1,4 @@
1
- import { n as AuthStore } from "../store-CRqU5WCe.mjs";
1
+ import { n as AuthStore } from "../store-F6n7TyY9.mjs";
2
2
  import { SignInMail } from "./mail.mjs";
3
3
  //#region src/auth/stand-in.d.ts
4
4
  interface StandIn {
@@ -1,5 +1,5 @@
1
1
  import { i as processEnv, r as platformApi, t as here } from "./here-BKjizr_N.mjs";
2
- import { d as userToken, o as connect, s as databaseUrl } from "./client-cU04Dzrt.mjs";
2
+ import { d as userToken, o as connect, s as databaseUrl } from "./client-DD0xZprk.mjs";
3
3
  import { sendSignInMail } from "./auth/mail.mjs";
4
4
  import "./files-DhPeWwcT.mjs";
5
5
  import { standIn } from "./auth/stand-in.mjs";
@@ -96,8 +96,11 @@ interface BoundDatabases {
96
96
  * (as after a move, its rows gone): true when that call should be sent once more.
97
97
  */
98
98
  remake?(binding: string, since: number): Promise<boolean>;
99
- /** Adds an entry to the `Server-Timing` of the request's response, where Midsummer turned that on for its own diagnostics. */
100
- note?(entry: string): void;
99
+ /**
100
+ * Adds an entry to the `Server-Timing` of the request's response, where Midsummer turned that on for its own
101
+ * diagnostics. An entry given as a function is read as the response is made, so a call still waiting then shows.
102
+ */
103
+ note?(entry: string | (() => string)): void;
101
104
  }
102
105
  /** What a user's token says of them beside their id, as the OIDC claims `name` and `email`, each at most `PROFILE_MOST` characters. */
103
106
  interface UserProfile {
@@ -849,22 +849,26 @@ const inPage = () => typeof globalThis.document !== "undefined";
849
849
  async function connect(options) {
850
850
  let url, token, refresh;
851
851
  const server = !("url" in options);
852
+ let through;
852
853
  if ("database" in options) {
853
854
  const door = options.database.door?.(options.binding);
854
855
  if (door) return facade(doorCalls(options.database, options.binding, door), doorScope(door));
856
+ through = options.database;
855
857
  const first = await options.database.token(options.binding);
856
858
  url = first.url;
857
859
  token = first.token;
858
- refresh = async () => (await options.database.token(options.binding)).token;
860
+ const handle = options.database;
861
+ refresh = async () => (await (served() ?? handle).token(options.binding)).token;
859
862
  } else if ("binding" in options) {
860
863
  const found = bound(options.binding);
861
864
  if ("handle" in found) {
862
865
  const door = found.handle.door?.(options.binding);
863
866
  if (door) return facade(doorCalls(found.handle, options.binding, door), doorScope(door));
867
+ through = found.handle;
864
868
  const first = await found.handle.token(options.binding);
865
869
  url = first.url;
866
870
  token = first.token;
867
- refresh = async () => (await found.handle.token(options.binding)).token;
871
+ refresh = async () => (await (served() ?? found.handle).token(options.binding)).token;
868
872
  } else if ("dev" in found) {
869
873
  url = found.dev;
870
874
  token = found.token;
@@ -890,7 +894,7 @@ async function connect(options) {
890
894
  token = options.token;
891
895
  refresh = options.refresh;
892
896
  }
893
- if (server || !inPage()) return opened(url, token, refresh, server, null);
897
+ if (server || !inPage()) return opened(url, token, refresh, server, null, through);
894
898
  let seen = await verifiedAt(url, token);
895
899
  if ("refused" in seen && refresh) {
896
900
  token = await refresh();
@@ -908,8 +912,11 @@ async function connect(options) {
908
912
  return fresh;
909
913
  })) ?? void 0, false, key);
910
914
  }
911
- /** A connection opened for `key`'s caller (null: one the Database did not vouch for), as `connect` describes it. */
912
- async function opened(url, token, refresh, server, key) {
915
+ /**
916
+ * A connection opened for `key`'s caller (null: one the Database did not vouch for), as `connect` describes it. One a
917
+ * request's handle made with no door (`through`) times its calls on the request it serves (`relayNoted`).
918
+ */
919
+ async function opened(url, token, refresh, server, key, through) {
913
920
  let connection;
914
921
  try {
915
922
  const apart = server ? {} : await isolation(url, key, token);
@@ -922,7 +929,43 @@ async function opened(url, token, refresh, server, key) {
922
929
  } catch (error) {
923
930
  throw await refusalAt(url, token) ?? error;
924
931
  }
925
- return facade(connection, scopeOf(token));
932
+ return facade(through ? relayNoted(connection, through) : connection, scopeOf(token));
933
+ }
934
+ /**
935
+ * A connection through a request's handle (no door: each call goes to the Database's address, which the handle relays),
936
+ * whose queries, mutations and actions each add a `db-relay` entry to the `Server-Timing` of the request they run in,
937
+ * where Midsummer asked for one (`note`): the function, and how long it took to answer or be refused. The entry is
938
+ * read as the response is made, so a call still waiting then says `unanswered` and how long it had waited, which shows
939
+ * a call that never reached the handle beside the dispatcher's own `db-relay` for each one that did.
940
+ */
941
+ function relayNoted(connection, handle) {
942
+ const timed = (fn, run) => {
943
+ const asker = served() ?? handle;
944
+ if (!asker.note) return run();
945
+ const started = performance.now();
946
+ let ended;
947
+ asker.note(() => `db-relay;dur=${ms(ended?.ms ?? performance.now() - started)};desc="${fn.name}, ${ended?.how ?? "unanswered"}"`);
948
+ const call = run();
949
+ call.then((answer) => {
950
+ ended = {
951
+ ms: performance.now() - started,
952
+ how: isRefusal(answer) ? `refused (${answer.why ?? answer.err ?? "refused"})` : "answered"
953
+ };
954
+ }, (error) => {
955
+ const refused = caught(error);
956
+ ended = {
957
+ ms: performance.now() - started,
958
+ how: `refused (${refused.why ?? refused.err ?? "refused"})`
959
+ };
960
+ });
961
+ return call;
962
+ };
963
+ return {
964
+ query: (fn, args) => timed(fn, () => connection.query(fn, args)),
965
+ mutation: (fn, args, options) => timed(fn, () => connection.mutation(fn, args, options)),
966
+ watchQuery: (fn, args, options, onValue) => connection.watchQuery(fn, args, options, onValue),
967
+ close: () => connection.close()
968
+ };
926
969
  }
927
970
  /** How long before its token runs out a door's calls renew it first. Every token a request hands has a minute or more left. */
928
971
  const DOOR_RENEW_MS = 3e4;
@@ -1348,7 +1391,11 @@ function doorCalls(handle, binding, first) {
1348
1391
  }
1349
1392
  /** The Database handle of the request being served, in a Deployment; undefined anywhere else. */
1350
1393
  const served = () => (globalThis[Symbol.for("midsummer.context")]?.())?.database;
1351
- /** The process's queries in flight, shared by every client that keeps nothing: every write any client makes goes through it. */
1394
+ /**
1395
+ * The process's queries in flight outside a Deployment's request, shared by every client there: every write any
1396
+ * client makes goes through it. A request's queries never share another request's call: a request's I/O ends with it,
1397
+ * so a call shared from a request that has answered would never answer.
1398
+ */
1352
1399
  const processMemo = new QueryMemo(false);
1353
1400
  /** Each Deployment request's kept answers, by the request's context (`here()`): never another request's. */
1354
1401
  const requestMemos = /* @__PURE__ */ new WeakMap();
@@ -1377,8 +1424,9 @@ const doorScope = (door) => ({
1377
1424
  });
1378
1425
  /**
1379
1426
  * The `Database` over a connection, a socket's or a door's (`Calls`), as `connect` describes it. Identical queries in
1380
- * flight at once share one call (`processMemo`). A door's client in a Deployment's request also keeps a query's answer
1381
- * for the rest of that request (`requestMemo`). Every mutation and action, through any client, clears what its request
1427
+ * flight at once share one call: in a Deployment's request, that request's alone (`requestMemo`), elsewhere the
1428
+ * process's (`processMemo`). A door's client in a Deployment's request also keeps a query's answer for the rest of
1429
+ * that request. Every mutation and action, through any client, clears what its request
1382
1430
  * keeps for its Database (every Database, where the client can't tell which) before it resolves, read from the request
1383
1431
  * it runs in, or else the one the client was made in. A watch is not touched.
1384
1432
  */
@@ -1401,7 +1449,7 @@ function facade(connection, scope) {
1401
1449
  return {
1402
1450
  async query(fn, ...[args]) {
1403
1451
  const context = here();
1404
- const value = await (scope.keeps && context ? requestMemo(context) : processMemo).read(scope.database, `${scope.who}\u0000${own}\u0000${callKey(fn.name, args)}`, () => readAgain(() => connection.query(call(fn), sent(args))), (answer) => !isRefusal(answer));
1452
+ const value = await (context ? requestMemo(context) : processMemo).read(scope.database, `${scope.who}\u0000${own}\u0000${callKey(fn.name, args)}`, () => readAgain(() => connection.query(call(fn), sent(args))), (answer) => scope.keeps && !isRefusal(answer));
1405
1453
  if (isRefusal(value)) throw refusal(value, true);
1406
1454
  return got(value);
1407
1455
  },
@@ -1,3 +1,3 @@
1
1
  import { n as DatabaseErrorCode, t as DatabaseError } from "../errors-CnQduDOt.mjs";
2
- import { C as userToken, S as signedInDatabase, _ as clerk, a as DATABASE_TOKEN_PATH, b as oidc, c as DatabaseToken, d as PROFILE_MOST, f as Reference, g as auth0, h as UserProfile, i as ConnectOptions, l as DoorToken, m as SignedInDatabase, n as AuthState, o as Database, p as ReturnsOf, r as BoundDatabases, s as DatabaseClient, t as ArgsOf, u as FetchToken, v as connect, x as profileClaims, y as databaseUrl } from "../client-BDjPQa7G.mjs";
2
+ import { C as userToken, S as signedInDatabase, _ as clerk, a as DATABASE_TOKEN_PATH, b as oidc, c as DatabaseToken, d as PROFILE_MOST, f as Reference, g as auth0, h as UserProfile, i as ConnectOptions, l as DoorToken, m as SignedInDatabase, n as AuthState, o as Database, p as ReturnsOf, r as BoundDatabases, s as DatabaseClient, t as ArgsOf, u as FetchToken, v as connect, x as profileClaims, y as databaseUrl } from "../client-D5AG590o.mjs";
3
3
  export { ArgsOf, AuthState, BoundDatabases, ConnectOptions, DATABASE_TOKEN_PATH, Database, DatabaseClient, DatabaseError, type DatabaseErrorCode, DatabaseToken, DoorToken, FetchToken, PROFILE_MOST, Reference, ReturnsOf, SignedInDatabase, UserProfile, auth0, clerk, connect, databaseUrl, oidc, profileClaims, signedInDatabase, userToken };
@@ -1,3 +1,3 @@
1
1
  import { DatabaseError } from "./errors.mjs";
2
- import { a as clerk, c as oidc, d as userToken, i as auth0, l as profileClaims, n as DatabaseClient, o as connect, r as PROFILE_MOST, s as databaseUrl, t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-cU04Dzrt.mjs";
2
+ import { a as clerk, c as oidc, d as userToken, i as auth0, l as profileClaims, n as DatabaseClient, o as connect, r as PROFILE_MOST, s as databaseUrl, t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-DD0xZprk.mjs";
3
3
  export { DATABASE_TOKEN_PATH, DatabaseClient, DatabaseError, PROFILE_MOST, auth0, clerk, connect, databaseUrl, oidc, profileClaims, signedInDatabase, userToken };
@@ -1,5 +1,5 @@
1
1
  import { t as DatabaseError } from "../errors-CnQduDOt.mjs";
2
- import { f as Reference, o as Database } from "../client-BDjPQa7G.mjs";
2
+ import { f as Reference, o as Database } from "../client-D5AG590o.mjs";
3
3
  import { ReactNode } from "react";
4
4
  //#region src/database/react.d.ts
5
5
  type ArgsOf<F> = F extends Reference<any, infer A, any> ? A : never;
@@ -1,4 +1,4 @@
1
- import { n as AuthStore } from "./store-CRqU5WCe.mjs";
1
+ import { n as AuthStore } from "./store-F6n7TyY9.mjs";
2
2
  import { n as CaptchaProvider, t as AuthSettings } from "./settings-Dz3irtlu.mjs";
3
3
  import { SignInMail } from "./auth/mail.mjs";
4
4
  //#region src/auth/events.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midsummer-ai/sdk",
3
- "version": "0.1.0-staging.3796",
3
+ "version": "0.1.0-staging.3802",
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.",
@@ -1,4 +1,4 @@
1
- import { o as Database } from "./client-BDjPQa7G.mjs";
1
+ import { o as Database } from "./client-D5AG590o.mjs";
2
2
  //#region src/auth/store.d.ts
3
3
  /** One of `db/auth.ts`'s functions. */
4
4
  type AuthCall = "create" | "findOne" | "findMany" | "count" | "update" | "updateMany" | "upsert" | "deleteMany" | "consume" | "increment" | "page";