@nivaro/react 0.3.7 → 0.3.9

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,57 +1,62 @@
1
- import { useQueryClient as f, useQuery as c } from "@tanstack/react-query";
2
- import { useNivaroClient as p } from "../../context.js";
3
- import { get as a } from "../../lib/commands.js";
4
- import { useLiveEvent as m } from "../../lib/live.js";
5
- import { prettyPagePath as g } from "../../lib/presence-state.js";
1
+ import { useQueryClient as y, useQuery as u } from "@tanstack/react-query";
2
+ import { useNivaroClient as a } from "../../context.js";
3
+ import { get as g } from "../../lib/commands.js";
4
+ import { useLiveEvent as h } from "../../lib/live.js";
5
+ import { usePresenceOnlinePoll as f } from "../../lib/presence-live.js";
6
+ import { presenceChangeTouches as P, prettyPagePath as m } from "../../lib/presence-state.js";
6
7
  import { PERSON_PROFILE_KEY as d } from "./types.js";
7
- function P(r) {
8
- var i, o;
9
- const s = p(), l = f();
10
- m(
8
+ function K(n) {
9
+ var t, o;
10
+ const l = a(), s = y();
11
+ h(
11
12
  "presence:changed",
12
13
  () => {
13
- l.invalidateQueries({ queryKey: [d, r] }), l.invalidateQueries({ queryKey: ["presence-online"] });
14
+ s.invalidateQueries(
15
+ { queryKey: [d, n] },
16
+ { cancelRefetch: !1 }
17
+ );
14
18
  },
15
19
  {
16
- enabled: !!r,
17
- debounceMs: 500,
20
+ enabled: !!n,
21
+ debounceMs: 1e3,
18
22
  includeOwn: !0,
19
- match: (t) => String((t == null ? void 0 : t.user_id) ?? "").toUpperCase() === String(r ?? "").toUpperCase()
23
+ // Coalesced server events list every changed id (`user_ids`); older ones carry `user_id`.
24
+ match: (i) => P(i, n)
20
25
  }
21
26
  );
22
- const { data: e } = c({
27
+ const c = f(15e3, !!n), { data: e } = u({
23
28
  queryKey: ["presence-online"],
24
- queryFn: () => s.request(
25
- a("/presence/online")
29
+ queryFn: () => l.request(
30
+ g("/presence/online")
26
31
  ),
27
- enabled: !!r,
28
- refetchInterval: 15e3,
32
+ enabled: !!n,
33
+ refetchInterval: c,
29
34
  staleTime: 5e3
30
- }), n = (i = e == null ? void 0 : e.data) == null ? void 0 : i.find(
31
- (t) => String(t.user_id).toUpperCase() === String(r ?? "").toUpperCase()
32
- ), u = (((o = e == null ? void 0 : e.config) == null ? void 0 : o.fields) ?? ["role", "page"]).includes("page");
33
- return { page: n && u ? n.page ?? g(n.current_path) : null };
35
+ }), r = (t = e == null ? void 0 : e.data) == null ? void 0 : t.find(
36
+ (i) => String(i.user_id).toUpperCase() === String(n ?? "").toUpperCase()
37
+ ), p = (((o = e == null ? void 0 : e.config) == null ? void 0 : o.fields) ?? ["role", "page"]).includes("page");
38
+ return { page: r && p ? r.page ?? m(r.current_path) : null };
34
39
  }
35
- function _(r, s) {
36
- var i, o;
37
- const l = p(), { data: e } = c({
40
+ function O(n, l) {
41
+ var t, o;
42
+ const s = a(), c = f(15e3, l && !!n), { data: e } = u({
38
43
  queryKey: ["presence-online"],
39
- queryFn: () => l.request(a("/presence/online")),
40
- enabled: s && !!r,
41
- refetchInterval: s ? 15e3 : !1,
44
+ queryFn: () => s.request(g("/presence/online")),
45
+ enabled: l && !!n,
46
+ refetchInterval: c,
42
47
  staleTime: 5e3
43
- }), n = (i = e == null ? void 0 : e.data) == null ? void 0 : i.find(
44
- (t) => String(t.user_id).toUpperCase() === String(r ?? "").toUpperCase()
48
+ }), r = (t = e == null ? void 0 : e.data) == null ? void 0 : t.find(
49
+ (i) => String(i.user_id).toUpperCase() === String(n ?? "").toUpperCase()
45
50
  );
46
- if (!n) return { word: null, page: null, minutes: null };
47
- const u = (((o = e == null ? void 0 : e.config) == null ? void 0 : o.fields) ?? ["role", "page"]).includes("page");
51
+ if (!r) return { word: null, page: null, minutes: null };
52
+ const p = (((o = e == null ? void 0 : e.config) == null ? void 0 : o.fields) ?? ["role", "page"]).includes("page");
48
53
  return {
49
- word: n.away ? "away" : n.is_idle ? "idle" : "online",
50
- page: u ? n.page ?? g(n.current_path) : null,
51
- minutes: n.idle_minutes ?? null
54
+ word: r.away ? "away" : r.is_idle ? "idle" : "online",
55
+ page: p ? r.page ?? m(r.current_path) : null,
56
+ minutes: r.idle_minutes ?? null
52
57
  };
53
58
  }
54
59
  export {
55
- _ as useCardPresence,
56
- P as usePersonPresence
60
+ O as useCardPresence,
61
+ K as usePersonPresence
57
62
  };
@@ -0,0 +1,54 @@
1
+ import { useQueryClient as d } from "@tanstack/react-query";
2
+ import { useEffect as E } from "react";
3
+ import { LIVE_WINDOW_EVENT as c } from "./live.js";
4
+ import { useLiveRefetchInterval as p } from "./live-queries.js";
5
+ import { useOptionalRealtime as w } from "./realtime.js";
6
+ const L = ["presence-online"], _ = 1e3, v = 6e4, f = /* @__PURE__ */ new WeakMap();
7
+ function a(n, t) {
8
+ t.timer || (t.timer = setTimeout(() => {
9
+ t.timer = null, n.invalidateQueries({ queryKey: [...L] }, { cancelRefetch: !1 });
10
+ }, _));
11
+ }
12
+ function P(n, t) {
13
+ var u;
14
+ let r = f.get(n);
15
+ if (!r) {
16
+ const i = {
17
+ refs: 0,
18
+ adapter: null,
19
+ offAdapter: null,
20
+ offWindow: () => {
21
+ },
22
+ timer: null
23
+ }, l = (m) => {
24
+ const o = m.detail;
25
+ (o == null ? void 0 : o.event) === "presence:changed" && a(n, i);
26
+ };
27
+ typeof window < "u" && (window.addEventListener(c, l), i.offWindow = () => window.removeEventListener(c, l)), r = i, f.set(n, r);
28
+ }
29
+ const e = r;
30
+ e.refs++, t && e.adapter !== t && ((u = e.offAdapter) == null || u.call(e), e.adapter = t, e.offAdapter = t.on("presence:changed", () => a(n, e)));
31
+ let s = !1;
32
+ return () => {
33
+ var i;
34
+ s || (s = !0, e.refs--, !(e.refs > 0) && ((i = e.offAdapter) == null || i.call(e), e.offWindow(), e.timer && clearTimeout(e.timer), f.delete(n)));
35
+ };
36
+ }
37
+ function N(n = !0) {
38
+ const t = d(), r = w();
39
+ E(() => {
40
+ if (n)
41
+ return P(t, r);
42
+ }, [t, r, n]);
43
+ }
44
+ function S(n, t = !0) {
45
+ return N(t), p(t ? n : !1, { safetyMs: v });
46
+ }
47
+ export {
48
+ L as PRESENCE_ONLINE_KEY,
49
+ v as PRESENCE_POLL_BACKSTOP_MS,
50
+ _ as PRESENCE_REFETCH_DELAY_MS,
51
+ P as acquirePresenceListener,
52
+ N as usePresenceOnlineLive,
53
+ S as usePresenceOnlinePoll
54
+ };
@@ -1,49 +1,57 @@
1
- function $(n) {
2
- const t = Math.max(0, Math.floor(n.minutes)), e = t >= 60 ? `${Math.floor(t / 60)}h ${t % 60}m` : `${t}m`;
3
- return n.label ? `stuck on ${n.label} for ${e}` : `stuck for ${e}`;
1
+ function m(t) {
2
+ const n = Math.max(0, Math.floor(t.minutes)), e = n >= 60 ? `${Math.floor(n / 60)}h ${n % 60}m` : `${n}m`;
3
+ return t.label ? `stuck on ${t.label} for ${e}` : `stuck for ${e}`;
4
4
  }
5
- function m(n) {
6
- if (!n) return null;
7
- const t = n.split("?")[0].split("/").filter(Boolean);
8
- if (t.length === 0) return "Home";
9
- const e = /* @__PURE__ */ new Set(["records", "collections", "p"]), o = t.filter((l) => !e.has(l));
10
- return o.length === 0 ? "Home" : o.map((l, r) => r === 0 ? l.replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()) : l).join(" › ");
5
+ function $(t) {
6
+ if (!t) return null;
7
+ const n = t.split("?")[0].split("/").filter(Boolean);
8
+ if (n.length === 0) return "Home";
9
+ const e = /* @__PURE__ */ new Set(["records", "collections", "p"]), o = n.filter((r) => !e.has(r));
10
+ return o.length === 0 ? "Home" : o.map((r, s) => s === 0 ? r.replace(/[-_]/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) : r).join(" › ");
11
11
  }
12
12
  const a = /* @__PURE__ */ new Set(["API", "admin"]);
13
- function d(n, t, e, o, l) {
14
- if (!n || !n.startsWith("/") || n.startsWith("//") || /[\\\s]/.test(n)) return null;
15
- const r = n.split("#")[0], c = /^\/(?:records|collections)\/([A-Za-z0-9_]+)\/([^/?#]+)/.exec(r);
16
- let s = null;
17
- c && c[2] !== "new" && o && (s = o(c[1], encodeURIComponent(c[2])));
18
- const i = (e == null ? void 0 : e.replace(/\/$/, "")) ?? "";
13
+ function d(t, n, e, o, r) {
14
+ if (!t || !t.startsWith("/") || t.startsWith("//") || /[\\\s]/.test(t)) return null;
15
+ const s = t.split("#")[0], l = /^\/(?:records|collections)\/([A-Za-z0-9_]+)\/([^/?#]+)/.exec(s);
19
16
  let u = null;
17
+ l && l[2] !== "new" && o && (u = o(l[1], encodeURIComponent(l[2])));
18
+ const i = (e == null ? void 0 : e.replace(/\/$/, "")) ?? "";
19
+ let c = null;
20
20
  try {
21
- u = i && l ? new URL(i, l).origin : null;
21
+ c = i && r ? new URL(i, r).origin : null;
22
22
  } catch {
23
- u = null;
23
+ c = null;
24
24
  }
25
- const f = !!u && u === l;
26
- return s || (t && a.has(t) ? s = f ? r : i ? `${i}${r}` : null : s = f ? null : r), p(s, l, u);
25
+ const f = !!c && c === r;
26
+ return u || (n && a.has(n) ? u = f ? s : i ? `${i}${s}` : null : u = f ? null : s), p(u, r, c);
27
27
  }
28
- function p(n, t, e) {
29
- if (!n || !t) return null;
28
+ function p(t, n, e) {
29
+ if (!t || !n) return null;
30
30
  try {
31
- const o = new URL(n, t);
32
- return o.protocol !== "http:" && o.protocol !== "https:" ? null : o.origin === t || o.origin === e ? n : null;
31
+ const o = new URL(t, n);
32
+ return o.protocol !== "http:" && o.protocol !== "https:" ? null : o.origin === n || o.origin === e ? t : null;
33
33
  } catch {
34
34
  return null;
35
35
  }
36
36
  }
37
- function h(n, t) {
38
- return /^https?:\/\//i.test(n) ? n : `${typeof window > "u" ? "" : window.location.origin}${n}`;
37
+ function g(t, n) {
38
+ return /^https?:\/\//i.test(t) ? t : `${typeof window > "u" ? "" : window.location.origin}${t}`;
39
+ }
40
+ function h(t) {
41
+ return t.online ? t.away ? "away" : (t.idle_minutes ?? 0) >= 5 ? "idle" : "online" : "offline";
39
42
  }
40
- function w(n) {
41
- return n.online ? n.away ? "away" : (n.idle_minutes ?? 0) >= 5 ? "idle" : "online" : "offline";
43
+ function y(t, n) {
44
+ if (!n) return !1;
45
+ const e = t ?? {};
46
+ if (e.many === !0) return !0;
47
+ const o = String(n).toUpperCase();
48
+ return Array.isArray(e.user_ids) && e.user_ids.some((r) => String(r).toUpperCase() === o) ? !0 : String(e.user_id ?? "").toUpperCase() === o;
42
49
  }
43
50
  export {
44
- h as fullHref,
51
+ g as fullHref,
52
+ y as presenceChangeTouches,
45
53
  d as presencePlaceHref,
46
- w as presenceWord,
47
- m as prettyPagePath,
48
- $ as stuckText
54
+ h as presenceWord,
55
+ $ as prettyPagePath,
56
+ m as stuckText
49
57
  };
@@ -1,19 +1,20 @@
1
- import { noteOwnWriteFromCommand as b } from "./own-writes.js";
1
+ import { noteOwnWriteFromCommand as C } from "./own-writes.js";
2
+ import { noteCredentialChanged as z, isIdentityRead as D, claimIdentityCall as M, signedOutError as $, noteSignedIn as Z, isSignedOutError as U, noteUnauthorized as x } from "./signed-out.js";
2
3
  function q(t) {
3
4
  if (!t || typeof t != "object") return "";
4
5
  const s = Object.entries(t).filter(([, o]) => o != null).map(([o, u]) => [o, String(u)]).sort(([o], [u]) => o < u ? -1 : o > u ? 1 : 0);
5
6
  return s.length ? new URLSearchParams(s).toString() : "";
6
7
  }
7
- function k(t) {
8
+ function P(t) {
8
9
  const s = (t._method ?? "GET").toUpperCase(), o = s === "GET" || t._body === void 0 ? "" : JSON.stringify(t._body);
9
10
  return `${s} ${t._path ?? ""} ${q(t._params)} ${o}`;
10
11
  }
11
- function g(t) {
12
+ function A(t) {
12
13
  return (t._method ?? "GET").toUpperCase() === "GET";
13
14
  }
14
- const P = /^\/(widgets-internal\/[^/]+\/render|items\/[^/]+\/[^/]+\/child-summary|items\/[^/]+\/auto-id-preview|config-conformance\/record\/.+\/check|pipelines\/instance\/[^/]+\/owners\/batch|addendums\/summary|at-risk\/evaluate|record-views\/.+\/touch)$/;
15
- function j(t) {
16
- return g(t) ? !0 : (t._method ?? "GET").toUpperCase() !== "POST" ? !1 : P.test((t._path ?? "").split("?")[0]);
15
+ const I = /^\/(widgets-internal\/[^/]+\/render|items\/[^/]+\/[^/]+\/child-summary|items\/[^/]+\/auto-id-preview|config-conformance\/record\/.+\/check|pipelines\/instance\/[^/]+\/owners\/batch|addendums\/summary|at-risk\/evaluate|record-views\/.+\/touch)$/;
16
+ function H(t) {
17
+ return A(t) ? !0 : (t._method ?? "GET").toUpperCase() !== "POST" ? !1 : I.test((t._path ?? "").split("?")[0]);
17
18
  }
18
19
  function T(t) {
19
20
  if (t == null || typeof t != "object") return t;
@@ -23,11 +24,11 @@ function T(t) {
23
24
  return t;
24
25
  }
25
26
  }
26
- const L = Symbol("nivaro.coalesced");
27
- function z(t) {
28
- return t[L] === !0;
27
+ const j = Symbol("nivaro.coalesced");
28
+ function B(t) {
29
+ return t[j] === !0;
29
30
  }
30
- const C = 20, D = /^\/items\/([A-Za-z_][A-Za-z0-9_]*)(?:\/([^/?#]+))?$/, I = /* @__PURE__ */ new Set(["aggregate", "export", "distinct", "resolve-paths", "batch-read"]), M = /* @__PURE__ */ new Set([
31
+ const O = 20, F = /^\/items\/([A-Za-z_][A-Za-z0-9_]*)(?:\/([^/?#]+))?$/, W = /* @__PURE__ */ new Set(["aggregate", "export", "distinct", "resolve-paths", "batch-read"]), K = /* @__PURE__ */ new Set([
31
32
  "fields",
32
33
  "filter",
33
34
  "sort",
@@ -40,32 +41,32 @@ const C = 20, D = /^\/items\/([A-Za-z_][A-Za-z0-9_]*)(?:\/([^/?#]+))?$/, I = /*
40
41
  "conditions",
41
42
  "labels"
42
43
  ]);
43
- function $(t) {
44
+ function Y(t) {
44
45
  const s = t;
45
46
  if ((s._method ?? "GET").toUpperCase() !== "GET") return null;
46
- const o = D.exec(s._path ?? "");
47
+ const o = F.exec(s._path ?? "");
47
48
  if (!o) return null;
48
49
  const [, u, d] = o;
49
- if (d !== void 0 && I.has(d)) return null;
50
- const m = s._params ?? {}, i = {};
50
+ if (d !== void 0 && W.has(d)) return null;
51
+ const m = s._params ?? {}, a = {};
51
52
  for (const [r, c] of Object.entries(m))
52
53
  if (c !== void 0) {
53
- if (!M.has(r)) return null;
54
- i[r] = c;
54
+ if (!K.has(r)) return null;
55
+ a[r] = c;
55
56
  }
56
- return d === void 0 ? { collection: u, query: i } : { collection: u, id: d, query: i };
57
+ return d === void 0 ? { collection: u, query: a } : { collection: u, id: d, query: a };
57
58
  }
58
- function Z(t) {
59
+ function J(t) {
59
60
  let s = [], o;
60
- const u = (i) => t.request(i.command).then(i.resolve, i.reject), d = async (i) => {
61
- if (i.length === 1) return u(i[0]);
61
+ const u = (a) => t.request(a.command).then(a.resolve, a.reject), d = async (a) => {
62
+ if (a.length === 1) return u(a[0]);
62
63
  let r;
63
64
  try {
64
65
  const c = await t.request({
65
66
  _method: "POST",
66
67
  _path: "/items/batch-read",
67
68
  _body: {
68
- reads: i.map((n, e) => ({
69
+ reads: a.map((n, e) => ({
69
70
  key: String(e),
70
71
  collection: n.read.collection,
71
72
  ...n.read.id !== void 0 ? { id: n.read.id } : {},
@@ -77,7 +78,7 @@ function Z(t) {
77
78
  } catch {
78
79
  r = void 0;
79
80
  }
80
- i.forEach((c, n) => {
81
+ a.forEach((c, n) => {
81
82
  const e = r == null ? void 0 : r[n];
82
83
  if ((e == null ? void 0 : e.status) !== 200 || e === void 0) {
83
84
  u(c);
@@ -87,36 +88,36 @@ function Z(t) {
87
88
  });
88
89
  }, m = () => {
89
90
  o = void 0;
90
- const i = s;
91
+ const a = s;
91
92
  s = [];
92
- for (let r = 0; r < i.length; r += C)
93
- d(i.slice(r, r + C));
93
+ for (let r = 0; r < a.length; r += O)
94
+ d(a.slice(r, r + O));
94
95
  };
95
- return (i, r) => new Promise((c, n) => {
96
+ return (a, r) => new Promise((c, n) => {
96
97
  s.push({
97
98
  read: r,
98
- command: i,
99
+ command: a,
99
100
  resolve: c,
100
101
  reject: n
101
102
  }), o === void 0 && (o = setTimeout(m, 0));
102
103
  });
103
104
  }
104
- const O = 50, x = 10, H = /^\/collections\/([A-Za-z_][A-Za-z0-9_-]{0,127})$/;
105
- function U(t) {
105
+ const b = 50, Q = 10, V = /^\/collections\/([A-Za-z_][A-Za-z0-9_-]{0,127})$/;
106
+ function X(t) {
106
107
  const s = t;
107
108
  if ((s._method ?? "GET").toUpperCase() !== "GET" || q(s._params) !== "") return null;
108
- const o = H.exec(s._path ?? "");
109
+ const o = V.exec(s._path ?? "");
109
110
  return o ? o[1] : null;
110
111
  }
111
- function B() {
112
+ function ee() {
112
113
  return Object.assign(new Error("Not found"), { status: 404, response: { error: "Not found" } });
113
114
  }
114
- function F(t) {
115
+ function te(t) {
115
116
  let s = !0, o = [], u;
116
117
  const d = (r) => t.request(r.command).then(r.resolve, r.reject), m = async (r) => {
117
- const c = [...new Set(r.map((a) => a.name))];
118
+ const c = [...new Set(r.map((i) => i.name))];
118
119
  if (c.length === 1 || !s) {
119
- for (const a of r) d(a);
120
+ for (const i of r) d(i);
120
121
  return;
121
122
  }
122
123
  let n;
@@ -126,11 +127,11 @@ function F(t) {
126
127
  _path: "/collections",
127
128
  _params: { names: c.join(",") }
128
129
  });
129
- } catch (a) {
130
- const h = a == null ? void 0 : a.status;
130
+ } catch (i) {
131
+ const h = i == null ? void 0 : i.status;
131
132
  if (h === 400 || h === 404 || h === 405) s = !1;
132
133
  else if (h === 429 || h !== void 0 && h >= 500) {
133
- for (const p of r) p.reject(a);
134
+ for (const p of r) p.reject(i);
134
135
  return;
135
136
  }
136
137
  n = void 0;
@@ -138,13 +139,13 @@ function F(t) {
138
139
  const e = n == null ? void 0 : n.data;
139
140
  if (!e || typeof e != "object" || Array.isArray(e)) {
140
141
  Array.isArray(e) && (s = !1);
141
- for (const a of r) d(a);
142
+ for (const i of r) d(i);
142
143
  return;
143
144
  }
144
145
  const l = e, f = new Set(Array.isArray(n == null ? void 0 : n.missing) ? n.missing : []);
145
- for (const a of r)
146
- Object.hasOwn(l, a.name) ? a.resolve({ data: T(l[a.name]) }) : f.has(a.name) ? a.reject(B()) : d(a);
147
- }, i = () => {
146
+ for (const i of r)
147
+ Object.hasOwn(l, i.name) ? i.resolve({ data: T(l[i.name]) }) : f.has(i.name) ? i.reject(ee()) : d(i);
148
+ }, a = () => {
148
149
  u = void 0;
149
150
  const r = o;
150
151
  o = [];
@@ -152,8 +153,8 @@ function F(t) {
152
153
  for (const e of r) {
153
154
  let l = n.get(e.name);
154
155
  if (!l) {
155
- const f = c[c.length - 1], a = f ? new Set(f.map((h) => h.name)).size : O;
156
- l = f && a < O ? f : [], l !== f && c.push(l), n.set(e.name, l);
156
+ const f = c[c.length - 1], i = f ? new Set(f.map((h) => h.name)).size : b;
157
+ l = f && i < b ? f : [], l !== f && c.push(l), n.set(e.name, l);
157
158
  }
158
159
  l.push(e);
159
160
  }
@@ -165,108 +166,125 @@ function F(t) {
165
166
  command: r,
166
167
  resolve: n,
167
168
  reject: e
168
- }), u === void 0 && (u = setTimeout(i, x));
169
+ }), u === void 0 && (u = setTimeout(a, Q));
169
170
  });
170
171
  }
171
- const R = 3e3, W = /^\/(collections\/[A-Za-z_][A-Za-z0-9_-]*|field-config\/[A-Za-z_][A-Za-z0-9_-]*|collection-layouts(\/active|\/summary\/[A-Za-z_][A-Za-z0-9_-]*)?|chat\/room-types|users\/me)$/, K = /^\/(record-views|item-locks|drafts|presence|rum|comments|notifications|tasks|field-rules\/evaluate|chat\/(?!room-types)|field-config\/[^/]+\/(evaluate-visibility|evaluate-defaults|evaluate-lock|cascade|project)$|items\/(?!nivaro_|directus_)[^/]+|users\/cards$|files\/verify$)/;
172
- function Y(t) {
172
+ const R = 3e3, ne = /^\/(collections\/[A-Za-z_][A-Za-z0-9_-]*|field-config\/[A-Za-z_][A-Za-z0-9_-]*|collection-layouts(\/active|\/summary\/[A-Za-z_][A-Za-z0-9_-]*)?|chat\/room-types|users\/me)$/, se = /^\/(record-views|item-locks|drafts|presence|rum|comments|notifications|tasks|field-rules\/evaluate|chat\/(?!room-types)|field-config\/[^/]+\/(evaluate-visibility|evaluate-defaults|evaluate-lock|cascade|project)$|items\/(?!nivaro_|directus_)[^/]+|users\/cards$|files\/verify$)/;
173
+ function oe(t) {
173
174
  const s = (t._path ?? "").split("?")[0];
174
- return (t._method ?? "GET").toUpperCase() === "POST" && P.test(s) ? !0 : K.test(s);
175
+ return (t._method ?? "GET").toUpperCase() === "POST" && I.test(s) ? !0 : se.test(s);
175
176
  }
176
- function J(t) {
177
+ function re(t) {
177
178
  const s = t;
178
- if (!g(s) || !W.test(s._path ?? "")) return !1;
179
+ if (!A(s) || !ne.test(s._path ?? "")) return !1;
179
180
  const o = s._params;
180
181
  return !(o && o.item != null && /^\/collection-layouts\/active$/.test(s._path ?? ""));
181
182
  }
182
- let v = 0;
183
- function G() {
184
- v++;
183
+ let y = 0;
184
+ function k() {
185
+ y++;
185
186
  }
186
- function ee(t, s = {}) {
187
- if (z(t)) return t;
188
- const o = /* @__PURE__ */ new Map(), u = s.batchReads ? Z(t) : null, d = s.batchCollections === !1 ? null : F(t), m = /* @__PURE__ */ new Map();
189
- let i = v;
187
+ function G(t, s) {
188
+ return t.then(
189
+ (o) => (s && Z(), o),
190
+ (o) => {
191
+ throw U(o, s) && x(s), o;
192
+ }
193
+ );
194
+ }
195
+ function le(t, s = {}) {
196
+ if (B(t)) return t;
197
+ const o = /* @__PURE__ */ new Map(), u = s.batchReads ? J(t) : null, d = s.batchCollections === !1 ? null : te(t), m = /* @__PURE__ */ new Map();
198
+ let a = y;
190
199
  const r = (n, e, l) => {
191
- if (e !== v) return;
192
- i !== v && (m.clear(), i = v);
200
+ if (e !== y) return;
201
+ a !== y && (m.clear(), a = y);
193
202
  const f = Date.now();
194
- for (const [a, h] of m) f - h.at >= R && m.delete(a);
203
+ for (const [i, h] of m) f - h.at >= R && m.delete(i);
195
204
  m.set(n, { at: f, epoch: e, value: l });
196
205
  }, c = (n) => {
197
206
  const e = n;
198
- if (!g(e)) {
199
- b(e._method, e._path, e._body);
200
- const _ = !Y(e);
201
- _ && G();
202
- const w = t.request(n);
203
- return (_ ? w.finally(G) : w).then((S) => (b(e._method, e._path, e._body, S), S));
207
+ if (!A(e)) {
208
+ C(e._method, e._path, e._body);
209
+ const _ = !oe(e);
210
+ _ && k();
211
+ const w = G(t.request(n), !1);
212
+ return (_ ? w.finally(k) : w).then((S) => (C(e._method, e._path, e._body, S), S));
204
213
  }
205
- const l = k(e), f = J(e);
214
+ const l = P(e), f = re(e);
206
215
  if (f) {
207
216
  const _ = m.get(l);
208
- if (_ && _.epoch === v && Date.now() - _.at < R)
217
+ if (_ && _.epoch === y && Date.now() - _.at < R)
209
218
  return Promise.resolve(T(_.value));
210
219
  }
211
- const a = o.get(l);
212
- if (a) return a.then(T);
213
- const h = u ? $(e) : null, p = !h && d ? U(e) : null, A = h && u ? u(n, h) : p && d ? d(n, p) : t.request(n), N = v, E = A.then((_) => (f && r(l, N, T(_)), _)).finally(() => {
214
- o.get(l) === E && o.delete(l);
220
+ const i = o.get(l);
221
+ if (i) return i.then(T);
222
+ const h = D(e._method, e._path, e._params);
223
+ if (h && !M()) return Promise.reject($());
224
+ const p = u ? Y(e) : null, E = !p && d ? X(e) : null, L = G(
225
+ p && u ? u(n, p) : E && d ? d(n, E) : t.request(n),
226
+ h
227
+ ), N = y, g = L.then((_) => (f && r(l, N, T(_)), _)).finally(() => {
228
+ o.get(l) === g && o.delete(l);
215
229
  });
216
- return o.set(l, E), E;
230
+ return o.set(l, g), g;
217
231
  };
218
232
  return new Proxy(t, {
219
233
  get(n, e, l) {
220
234
  if (e === "request") return c;
221
- if (e === L) return !0;
235
+ if (e === j) return !0;
236
+ if (e === "setToken" && typeof n.setToken == "function")
237
+ return (i) => {
238
+ n.setToken(i), z();
239
+ };
222
240
  const f = Reflect.get(n, e, l);
223
241
  return typeof f == "function" ? f.bind(n) : f;
224
242
  }
225
243
  });
226
244
  }
227
- const Q = /^\/(item-locks|drafts|auth)\b/, y = /* @__PURE__ */ new Set();
228
- function V() {
229
- for (const t of [...y]) t();
245
+ const ie = /^\/(item-locks|drafts|auth)\b/, v = /* @__PURE__ */ new Set();
246
+ function ae() {
247
+ for (const t of [...v]) t();
230
248
  }
231
- function te(t) {
249
+ function fe(t) {
232
250
  return t.subscribe((s) => {
233
- s.type === "observerAdded" && s.query.state.fetchStatus === "fetching" && y.size !== 0 && V();
251
+ s.type === "observerAdded" && s.query.state.fetchStatus === "fetching" && v.size !== 0 && ae();
234
252
  });
235
253
  }
236
- function ne(t, s = {}) {
254
+ function de(t, s = {}) {
237
255
  let o = s.open ?? !0, u;
238
256
  const d = /* @__PURE__ */ new Map(), m = () => {
239
257
  const n = [...d.values()];
240
258
  d.clear();
241
259
  for (const e of n) e.release();
242
- }, i = () => {
243
- y.delete(i), m();
260
+ }, a = () => {
261
+ v.delete(a), m();
244
262
  }, r = (n) => {
245
263
  const e = n;
246
- if (o || !j(e) || Q.test(e._path ?? "")) return t.request(n);
247
- const l = k(e), f = d.get(l);
264
+ if (o || !H(e) || ie.test(e._path ?? "")) return t.request(n);
265
+ const l = P(e), f = d.get(l);
248
266
  if (f) return f.promise.then(T);
249
- let a = () => {
267
+ let i = () => {
250
268
  };
251
- const p = new Promise((A) => {
252
- a = A;
269
+ const p = new Promise((E) => {
270
+ i = E;
253
271
  }).then(() => t.request(n));
254
- return d.set(l, { promise: p, release: a }), y.add(i), p;
272
+ return d.set(l, { promise: p, release: i }), v.add(a), p;
255
273
  };
256
274
  return new Proxy(t, {
257
275
  get(n, e, l) {
258
276
  if (e === "request") return r;
259
277
  if (e === "open") return o;
260
278
  if (e === "setOpen")
261
- return (a) => {
279
+ return (i) => {
262
280
  u !== void 0 && (clearTimeout(u), u = void 0);
263
281
  const h = o;
264
- o = a, a && !h && (y.delete(i), m());
282
+ o = i, i && !h && (v.delete(a), m());
265
283
  };
266
284
  if (e === "dispose")
267
285
  return () => {
268
286
  u === void 0 && (u = setTimeout(() => {
269
- u = void 0, o = !0, y.delete(i), m();
287
+ u = void 0, o = !0, v.delete(a), m();
270
288
  }, 0));
271
289
  };
272
290
  const f = Reflect.get(n, e, l);
@@ -275,17 +293,17 @@ function ne(t, s = {}) {
275
293
  });
276
294
  }
277
295
  export {
278
- C as BATCH_READ_LIMIT,
279
- O as COLLECTION_BATCH_LIMIT,
280
- x as COLLECTION_BATCH_WINDOW_MS,
296
+ O as BATCH_READ_LIMIT,
297
+ b as COLLECTION_BATCH_LIMIT,
298
+ Q as COLLECTION_BATCH_WINDOW_MS,
281
299
  R as SETTLED_READ_MS,
282
- U as batchableCollectionMeta,
283
- $ as batchableRead,
284
- ne as createGatedClient,
285
- G as forgetSettledReads,
286
- z as isCoalesced,
287
- J as isSettledRead,
288
- V as releaseGatedReads,
289
- te as releaseGatedReadsOnSharedFetch,
290
- ee as withGetCoalescing
300
+ X as batchableCollectionMeta,
301
+ Y as batchableRead,
302
+ de as createGatedClient,
303
+ k as forgetSettledReads,
304
+ B as isCoalesced,
305
+ re as isSettledRead,
306
+ ae as releaseGatedReads,
307
+ fe as releaseGatedReadsOnSharedFetch,
308
+ le as withGetCoalescing
291
309
  };