@midsummer-ai/sdk 0.1.0-staging.3874 → 0.1.0-staging.3880

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/auth/contract.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { r as AuthError } from "../auth-BCYdfoxn.mjs";
1
+ import { r as AuthError } from "../auth-uYveadHe.mjs";
2
2
  import { d as SETTINGS_TTL_MS, n as LIMIT_WINDOW_MS, t as LIMITS } from "../guard-Br3K8CVx.mjs";
3
3
  import { IMPERSONATION_TOKEN_MS, startImpersonation } from "./impersonate.mjs";
4
4
  //#region src/auth/contract.ts
package/auth/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as SESSION_CACHE_S, c 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-BCYdfoxn.mjs";
1
+ import { a as SESSION_CACHE_S, c 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-uYveadHe.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-Bj5NBIbS.mjs";
1
+ import { t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-DgqbFGUG.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-BJzVvUKV.mjs";
4
4
  import { a as shapeAttributes, r as ICONS, t as qrPath } from "../qr-BySxqLW6.mjs";
@@ -1,5 +1,5 @@
1
1
  import { a as processEnv, i as platformApi, n as here } from "./here-C2jhTheQ.mjs";
2
- import { d as userToken, o as connect, s as databaseUrl } from "./client-Bj5NBIbS.mjs";
2
+ import { d as userToken, o as connect, s as databaseUrl } from "./client-DgqbFGUG.mjs";
3
3
  import { sendSignInMail } from "./auth/mail.mjs";
4
4
  import "./files-DhPeWwcT.mjs";
5
5
  import { standIn } from "./auth/stand-in.mjs";
@@ -1,7 +1,7 @@
1
1
  import { i as platformApi, n as here, t as clientHeaders } from "./here-C2jhTheQ.mjs";
2
2
  import { n as bytesTagged, r as bytesUntagged } from "./bytes-C2pcyl9u.mjs";
3
3
  import { DatabaseError } from "./database/errors.mjs";
4
- import { a as socketAt, i as payloadOf, r as fetchAt, t as Connection } from "./connection-CpT0x1EE.mjs";
4
+ import { a as socketAt, i as payloadOf, r as fetchAt, t as Connection } from "./connection-Dh3mUykO.mjs";
5
5
  import { t as callKey } from "./key-BrRdFY-n.mjs";
6
6
  //#region src/database/door-socket.ts
7
7
  /**
@@ -851,7 +851,7 @@ async function isolation(url, key, token) {
851
851
  return {
852
852
  ...own,
853
853
  name,
854
- store: (await import("./store-Ch931wwA.mjs")).idbStore(name)
854
+ store: (await import("./store-DiKJeTrj.mjs")).idbStore(name)
855
855
  };
856
856
  }
857
857
  const inPage = () => typeof globalThis.document !== "undefined";
@@ -262,8 +262,20 @@ const rowKey = (tb, id, as) => as === void 0 ? `${tb}/${id}` : `${tb}/${id}@${as
262
262
  const asOf = (as) => as === void 0 || as === null ? {} : { as: String(as) };
263
263
  /** A server function named by its reference (`api.pay`: `{ name, kind }`, the seal's functions/_generated/api.mjs) or its name. */
264
264
  const fnName = (f) => f !== null && typeof f === "object" && typeof f.name === "string" ? f.name : f;
265
- /** The process's server sockets: url|token -> the Connection (one socket per process, however often connected). */
265
+ /** The process's server sockets: url|token -> the Connection (one socket per process, however often connected).
266
+ * In a Worker a socket lasts only as long as the request that opened it, so a later request's calls on it would never
267
+ * be answered: there nothing is shared by the process. `scope` (an object that lives as long as the request, as its
268
+ * handle does) shares one Connection within that request; a connect with no `scope` gets its own. */
266
269
  const SHARED = /* @__PURE__ */ new Map();
270
+ const SCOPED = /* @__PURE__ */ new WeakMap();
271
+ const sharedIn = (scope) => {
272
+ let m = SCOPED.get(scope);
273
+ if (!m) {
274
+ m = /* @__PURE__ */ new Map();
275
+ SCOPED.set(scope, m);
276
+ }
277
+ return m;
278
+ };
267
279
  /** (A11) W-TinyLFU: which keys a bounded cache keeps. New keys enter a small window LRU (1%); a key leaving the
268
280
  * window is admitted to the main LRU only if a count-min sketch (4 rows of 4-bit-ish counters, halved every 10x the
269
281
  * size in accesses) says it is used more often than the main LRU's victim. `touch` every access (hit or miss), `add`
@@ -387,19 +399,26 @@ var Connection = class Connection {
387
399
  if (shape === "binding") throw Object.assign(/* @__PURE__ */ new Error("connect over the network with a server token: a binding is not part of this client"), { code: "binding" });
388
400
  if (shape === "server") {
389
401
  const key = `${url}|${options.token ?? ""}`;
390
- let p = SHARED.get(key);
402
+ const scoped = options.scope !== null && typeof options.scope === "object";
403
+ if (!scoped && globalThis.WebSocketPair !== void 0) return Connection.open(url, {
404
+ ...options,
405
+ shape
406
+ });
407
+ const shared = scoped ? sharedIn(options.scope) : SHARED;
408
+ let p = shared.get(key);
391
409
  if (!p) {
392
410
  p = Connection.open(url, {
393
411
  ...options,
394
412
  shape
395
413
  }).then((g) => {
396
414
  g.sharedKey = key;
415
+ g.sharedBy = shared;
397
416
  return g;
398
417
  }, (e) => {
399
- SHARED.delete(key);
418
+ shared.delete(key);
400
419
  throw e;
401
420
  });
402
- SHARED.set(key, p);
421
+ shared.set(key, p);
403
422
  }
404
423
  const g = await p;
405
424
  g.refs += 1;
@@ -409,8 +428,8 @@ var Connection = class Connection {
409
428
  ...options,
410
429
  shape
411
430
  };
412
- if (o.store === void 0 && typeof indexedDB !== "undefined" && typeof document !== "undefined") o.store = (await import("./store-Ch931wwA.mjs")).idbStore(new URL(url).host);
413
- if (o.tabs !== false && typeof document !== "undefined") return (await import("./tabs-C4NDJzfK.mjs")).ConnectionTabs.connect(url, o);
431
+ if (o.store === void 0 && typeof indexedDB !== "undefined" && typeof document !== "undefined") o.store = (await import("./store-DiKJeTrj.mjs")).idbStore(new URL(url).host);
432
+ if (o.tabs !== false && typeof document !== "undefined") return (await import("./tabs-DDT9OkEv.mjs")).ConnectionTabs.connect(url, o);
414
433
  return Connection.open(url, o);
415
434
  }
416
435
  /** A Connection over one socket, of the shape given (default "browser"), no detection (tabs.mjs opens its own so). */
@@ -1892,10 +1911,10 @@ var Connection = class Connection {
1892
1911
  a: args
1893
1912
  }, listener, { as });
1894
1913
  }
1895
- /** Closes the socket. A server shape's socket is the process's: it closes when every `connect` closed it. */
1914
+ /** Closes the socket. A shared server socket (the process's, or a request's `scope`'s) closes when every `connect` closed it. */
1896
1915
  close() {
1897
1916
  if (this.sharedKey && (this.refs -= 1) > 0) return;
1898
- if (this.sharedKey && SHARED.get(this.sharedKey)) SHARED.delete(this.sharedKey);
1917
+ if (this.sharedKey && this.sharedBy.get(this.sharedKey)) this.sharedBy.delete(this.sharedKey);
1899
1918
  this.closed = true;
1900
1919
  clearInterval(this.dog);
1901
1920
  clearTimeout(this.renewer);
@@ -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-Bj5NBIbS.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-DgqbFGUG.mjs";
3
3
  export { DATABASE_TOKEN_PATH, DatabaseClient, DatabaseError, PROFILE_MOST, auth0, clerk, connect, databaseUrl, oidc, profileClaims, signedInDatabase, userToken };
package/here-C2jhTheQ.mjs CHANGED
@@ -12,7 +12,7 @@ function processEnv() {
12
12
  * This package's version: `0.0.0-dev` here, and in a published package the version it was published at, which the
13
13
  * release writes in its place as it stages the package (`stampSdk` in `scripts/release/packages.ts`).
14
14
  */
15
- const SDK_VERSION = "0.1.0-staging.3874";
15
+ const SDK_VERSION = "0.1.0-staging.3880";
16
16
  /**
17
17
  * The header that tells Midsummer which client made each of this package's calls: `Midsummer-Client: sdk/<version>
18
18
  * <part>`, `part` the product whose client it is (`database`, `storage`, `queues`, ...), so the platform counts which
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midsummer-ai/sdk",
3
- "version": "0.1.0-staging.3874",
3
+ "version": "0.1.0-staging.3880",
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 "./connection-CpT0x1EE.mjs";
1
+ import "./connection-Dh3mUykO.mjs";
2
2
  //#region src/database/client/store.mjs
3
3
  const STORES = [
4
4
  "ops",
@@ -1,4 +1,4 @@
1
- import { t as Connection } from "./connection-CpT0x1EE.mjs";
1
+ import { t as Connection } from "./connection-Dh3mUykO.mjs";
2
2
  //#region src/database/client/tabs.mjs
3
3
  /** Argument index of the options that take a `tag` (a tab tags its own writes: the same tag after a handover). */
4
4
  const TAGGED = {