@nivaro/react 0.3.3 → 0.3.5

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,31 +1,31 @@
1
- import { noteOwnWriteFromCommand as w } from "./own-writes.js";
2
- function R(e) {
3
- if (!e || typeof e != "object") return "";
4
- const o = Object.entries(e).filter(([, s]) => s != null).map(([s, u]) => [s, String(u)]).sort(([s], [u]) => s < u ? -1 : s > u ? 1 : 0);
5
- return o.length ? new URLSearchParams(o).toString() : "";
1
+ import { noteOwnWriteFromCommand as b } from "./own-writes.js";
2
+ function q(t) {
3
+ if (!t || typeof t != "object") return "";
4
+ 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
+ return s.length ? new URLSearchParams(s).toString() : "";
6
6
  }
7
- function k(e) {
8
- const o = (e._method ?? "GET").toUpperCase(), s = o === "GET" || e._body === void 0 ? "" : JSON.stringify(e._body);
9
- return `${o} ${e._path ?? ""} ${R(e._params)} ${s}`;
7
+ function k(t) {
8
+ const s = (t._method ?? "GET").toUpperCase(), o = s === "GET" || t._body === void 0 ? "" : JSON.stringify(t._body);
9
+ return `${s} ${t._path ?? ""} ${q(t._params)} ${o}`;
10
10
  }
11
- function A(e) {
12
- return (e._method ?? "GET").toUpperCase() === "GET";
11
+ function g(t) {
12
+ return (t._method ?? "GET").toUpperCase() === "GET";
13
13
  }
14
- const q = /^\/(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 N(e) {
16
- return A(e) ? !0 : (e._method ?? "GET").toUpperCase() !== "POST" ? !1 : q.test((e._path ?? "").split("?")[0]);
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]);
17
17
  }
18
- function y(e) {
19
- if (e == null || typeof e != "object") return e;
18
+ function T(t) {
19
+ if (t == null || typeof t != "object") return t;
20
20
  try {
21
- return structuredClone(e);
21
+ return structuredClone(t);
22
22
  } catch {
23
- return e;
23
+ return t;
24
24
  }
25
25
  }
26
- const G = Symbol("nivaro.coalesced");
27
- function j(e) {
28
- return e[G] === !0;
26
+ const L = Symbol("nivaro.coalesced");
27
+ function z(t) {
28
+ return t[L] === !0;
29
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
31
  "fields",
@@ -40,240 +40,252 @@ const C = 20, D = /^\/items\/([A-Za-z_][A-Za-z0-9_]*)(?:\/([^/?#]+))?$/, I = /*
40
40
  "conditions",
41
41
  "labels"
42
42
  ]);
43
- function $(e) {
44
- const o = e;
45
- if ((o._method ?? "GET").toUpperCase() !== "GET") return null;
46
- const s = D.exec(o._path ?? "");
47
- if (!s) return null;
48
- const [, u, d] = s;
43
+ function $(t) {
44
+ const s = t;
45
+ if ((s._method ?? "GET").toUpperCase() !== "GET") return null;
46
+ const o = D.exec(s._path ?? "");
47
+ if (!o) return null;
48
+ const [, u, d] = o;
49
49
  if (d !== void 0 && I.has(d)) return null;
50
- const m = o._params ?? {}, l = {};
51
- for (const [a, r] of Object.entries(m))
52
- if (r !== void 0) {
53
- if (!M.has(a)) return null;
54
- l[a] = r;
50
+ const m = s._params ?? {}, i = {};
51
+ for (const [r, c] of Object.entries(m))
52
+ if (c !== void 0) {
53
+ if (!M.has(r)) return null;
54
+ i[r] = c;
55
55
  }
56
- return d === void 0 ? { collection: u, query: l } : { collection: u, id: d, query: l };
56
+ return d === void 0 ? { collection: u, query: i } : { collection: u, id: d, query: i };
57
57
  }
58
- function z(e) {
59
- let o = [], s;
60
- const u = (l) => e.request(l.command).then(l.resolve, l.reject), d = async (l) => {
61
- if (l.length === 1) return u(l[0]);
62
- let a;
58
+ function Z(t) {
59
+ 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]);
62
+ let r;
63
63
  try {
64
- const r = await e.request({
64
+ const c = await t.request({
65
65
  _method: "POST",
66
66
  _path: "/items/batch-read",
67
67
  _body: {
68
- reads: l.map((n, t) => ({
69
- key: String(t),
68
+ reads: i.map((n, e) => ({
69
+ key: String(e),
70
70
  collection: n.read.collection,
71
71
  ...n.read.id !== void 0 ? { id: n.read.id } : {},
72
72
  query: n.read.query
73
73
  }))
74
74
  }
75
75
  });
76
- a = Array.isArray(r == null ? void 0 : r.results) ? r.results : void 0;
76
+ r = Array.isArray(c == null ? void 0 : c.results) ? c.results : void 0;
77
77
  } catch {
78
- a = void 0;
78
+ r = void 0;
79
79
  }
80
- l.forEach((r, n) => {
81
- const t = a == null ? void 0 : a[n];
82
- if ((t == null ? void 0 : t.status) !== 200 || t === void 0) {
83
- u(r);
80
+ i.forEach((c, n) => {
81
+ const e = r == null ? void 0 : r[n];
82
+ if ((e == null ? void 0 : e.status) !== 200 || e === void 0) {
83
+ u(c);
84
84
  return;
85
85
  }
86
- r.resolve(r.read.id !== void 0 ? { data: t.data } : { data: t.data, ...t.meta ?? {} });
86
+ c.resolve(c.read.id !== void 0 ? { data: e.data } : { data: e.data, ...e.meta ?? {} });
87
87
  });
88
88
  }, m = () => {
89
- s = void 0;
90
- const l = o;
91
- o = [];
92
- for (let a = 0; a < l.length; a += C)
93
- d(l.slice(a, a + C));
89
+ o = void 0;
90
+ const i = s;
91
+ s = [];
92
+ for (let r = 0; r < i.length; r += C)
93
+ d(i.slice(r, r + C));
94
94
  };
95
- return (l, a) => new Promise((r, n) => {
96
- o.push({
97
- read: a,
98
- command: l,
99
- resolve: r,
95
+ return (i, r) => new Promise((c, n) => {
96
+ s.push({
97
+ read: r,
98
+ command: i,
99
+ resolve: c,
100
100
  reject: n
101
- }), s === void 0 && (s = setTimeout(m, 0));
101
+ }), o === void 0 && (o = setTimeout(m, 0));
102
102
  });
103
103
  }
104
- const S = 50, Z = 10, x = /^\/collections\/([A-Za-z_][A-Za-z0-9_-]{0,127})$/;
105
- function U(e) {
106
- const o = e;
107
- if ((o._method ?? "GET").toUpperCase() !== "GET" || R(o._params) !== "") return null;
108
- const s = x.exec(o._path ?? "");
109
- return s ? s[1] : null;
104
+ const O = 50, x = 10, H = /^\/collections\/([A-Za-z_][A-Za-z0-9_-]{0,127})$/;
105
+ function U(t) {
106
+ const s = t;
107
+ if ((s._method ?? "GET").toUpperCase() !== "GET" || q(s._params) !== "") return null;
108
+ const o = H.exec(s._path ?? "");
109
+ return o ? o[1] : null;
110
110
  }
111
111
  function B() {
112
112
  return Object.assign(new Error("Not found"), { status: 404, response: { error: "Not found" } });
113
113
  }
114
- function H(e) {
115
- let o = !0, s = [], u;
116
- const d = (a) => e.request(a.command).then(a.resolve, a.reject), m = async (a) => {
117
- const r = [...new Set(a.map((c) => c.name))];
118
- if (r.length === 1 || !o) {
119
- for (const c of a) d(c);
114
+ function F(t) {
115
+ let s = !0, o = [], u;
116
+ 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
+ if (c.length === 1 || !s) {
119
+ for (const a of r) d(a);
120
120
  return;
121
121
  }
122
122
  let n;
123
123
  try {
124
- n = await e.request({
124
+ n = await t.request({
125
125
  _method: "GET",
126
126
  _path: "/collections",
127
- _params: { names: r.join(",") }
127
+ _params: { names: c.join(",") }
128
128
  });
129
- } catch (c) {
130
- const h = c == null ? void 0 : c.status;
131
- if (h === 400 || h === 404 || h === 405) o = !1;
129
+ } catch (a) {
130
+ const h = a == null ? void 0 : a.status;
131
+ if (h === 400 || h === 404 || h === 405) s = !1;
132
132
  else if (h === 429 || h !== void 0 && h >= 500) {
133
- for (const v of a) v.reject(c);
133
+ for (const p of r) p.reject(a);
134
134
  return;
135
135
  }
136
136
  n = void 0;
137
137
  }
138
- const t = n == null ? void 0 : n.data;
139
- if (!t || typeof t != "object" || Array.isArray(t)) {
140
- Array.isArray(t) && (o = !1);
141
- for (const c of a) d(c);
138
+ const e = n == null ? void 0 : n.data;
139
+ if (!e || typeof e != "object" || Array.isArray(e)) {
140
+ Array.isArray(e) && (s = !1);
141
+ for (const a of r) d(a);
142
142
  return;
143
143
  }
144
- const i = t, f = new Set(Array.isArray(n == null ? void 0 : n.missing) ? n.missing : []);
145
- for (const c of a)
146
- Object.hasOwn(i, c.name) ? c.resolve({ data: y(i[c.name]) }) : f.has(c.name) ? c.reject(B()) : d(c);
147
- }, l = () => {
144
+ 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 = () => {
148
148
  u = void 0;
149
- const a = s;
150
- s = [];
151
- const r = [], n = /* @__PURE__ */ new Map();
152
- for (const t of a) {
153
- let i = n.get(t.name);
154
- if (!i) {
155
- const f = r[r.length - 1], c = f ? new Set(f.map((h) => h.name)).size : S;
156
- i = f && c < S ? f : [], i !== f && r.push(i), n.set(t.name, i);
149
+ const r = o;
150
+ o = [];
151
+ const c = [], n = /* @__PURE__ */ new Map();
152
+ for (const e of r) {
153
+ let l = n.get(e.name);
154
+ 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);
157
157
  }
158
- i.push(t);
158
+ l.push(e);
159
159
  }
160
- for (const t of r) m(t);
160
+ for (const e of c) m(e);
161
161
  };
162
- return (a, r) => new Promise((n, t) => {
163
- s.push({
164
- name: r,
165
- command: a,
162
+ return (r, c) => new Promise((n, e) => {
163
+ o.push({
164
+ name: c,
165
+ command: r,
166
166
  resolve: n,
167
- reject: t
168
- }), u === void 0 && (u = setTimeout(l, Z));
167
+ reject: e
168
+ }), u === void 0 && (u = setTimeout(i, x));
169
169
  });
170
170
  }
171
- const b = 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)$/, F = /^\/(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 K(e) {
173
- const o = (e._path ?? "").split("?")[0];
174
- return (e._method ?? "GET").toUpperCase() === "POST" && q.test(o) ? !0 : F.test(o);
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) {
173
+ const s = (t._path ?? "").split("?")[0];
174
+ return (t._method ?? "GET").toUpperCase() === "POST" && P.test(s) ? !0 : K.test(s);
175
175
  }
176
- function Y(e) {
177
- const o = e;
178
- if (!A(o) || !W.test(o._path ?? "")) return !1;
179
- const s = o._params;
180
- return !(s && s.item != null && /^\/collection-layouts\/active$/.test(o._path ?? ""));
176
+ function J(t) {
177
+ const s = t;
178
+ if (!g(s) || !W.test(s._path ?? "")) return !1;
179
+ const o = s._params;
180
+ return !(o && o.item != null && /^\/collection-layouts\/active$/.test(s._path ?? ""));
181
181
  }
182
- let p = 0;
183
- function O() {
184
- p++;
182
+ let v = 0;
183
+ function G() {
184
+ v++;
185
185
  }
186
- function V(e, o = {}) {
187
- if (j(e)) return e;
188
- const s = /* @__PURE__ */ new Map(), u = o.batchReads ? z(e) : null, d = o.batchCollections === !1 ? null : H(e), m = /* @__PURE__ */ new Map();
189
- let l = p;
190
- const a = (n, t, i) => {
191
- if (t !== p) return;
192
- l !== p && (m.clear(), l = p);
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;
190
+ const r = (n, e, l) => {
191
+ if (e !== v) return;
192
+ i !== v && (m.clear(), i = v);
193
193
  const f = Date.now();
194
- for (const [c, h] of m) f - h.at >= b && m.delete(c);
195
- m.set(n, { at: f, epoch: t, value: i });
196
- }, r = (n) => {
197
- const t = n;
198
- if (!A(t)) {
199
- w(t._method, t._path, t._body);
200
- const _ = !K(t);
201
- _ && O();
202
- const E = e.request(n);
203
- return (_ ? E.finally(O) : E).then((g) => (w(t._method, t._path, t._body, g), g));
194
+ for (const [a, h] of m) f - h.at >= R && m.delete(a);
195
+ m.set(n, { at: f, epoch: e, value: l });
196
+ }, c = (n) => {
197
+ 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));
204
204
  }
205
- const i = k(t), f = Y(t);
205
+ const l = k(e), f = J(e);
206
206
  if (f) {
207
- const _ = m.get(i);
208
- if (_ && _.epoch === p && Date.now() - _.at < b)
209
- return Promise.resolve(y(_.value));
207
+ const _ = m.get(l);
208
+ if (_ && _.epoch === v && Date.now() - _.at < R)
209
+ return Promise.resolve(T(_.value));
210
210
  }
211
- const c = s.get(i);
212
- if (c) return c.then(y);
213
- const h = u ? $(t) : null, v = !h && d ? U(t) : null, P = h && u ? u(n, h) : v && d ? d(n, v) : e.request(n), L = p, T = P.then((_) => (f && a(i, L, y(_)), _)).finally(() => {
214
- s.get(i) === T && s.delete(i);
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);
215
215
  });
216
- return s.set(i, T), T;
216
+ return o.set(l, E), E;
217
217
  };
218
- return new Proxy(e, {
219
- get(n, t, i) {
220
- if (t === "request") return r;
221
- if (t === G) return !0;
222
- const f = Reflect.get(n, t, i);
218
+ return new Proxy(t, {
219
+ get(n, e, l) {
220
+ if (e === "request") return c;
221
+ if (e === L) return !0;
222
+ const f = Reflect.get(n, e, l);
223
223
  return typeof f == "function" ? f.bind(n) : f;
224
224
  }
225
225
  });
226
226
  }
227
- const J = /^\/(item-locks|drafts|auth)\b/;
228
- function X(e, o = {}) {
229
- let s = o.open ?? !0, u;
227
+ const Q = /^\/(item-locks|drafts|auth)\b/, y = /* @__PURE__ */ new Set();
228
+ function V() {
229
+ for (const t of [...y]) t();
230
+ }
231
+ function te(t) {
232
+ return t.subscribe((s) => {
233
+ s.type === "observerAdded" && s.query.state.fetchStatus === "fetching" && y.size !== 0 && V();
234
+ });
235
+ }
236
+ function ne(t, s = {}) {
237
+ let o = s.open ?? !0, u;
230
238
  const d = /* @__PURE__ */ new Map(), m = () => {
231
- const r = [...d.values()];
239
+ const n = [...d.values()];
232
240
  d.clear();
233
- for (const n of r) n.release();
234
- }, l = (r) => {
235
- const n = r;
236
- if (s || !N(n) || J.test(n._path ?? "")) return e.request(r);
237
- const t = k(n), i = d.get(t);
238
- if (i) return i.promise.then(y);
239
- let f = () => {
241
+ for (const e of n) e.release();
242
+ }, i = () => {
243
+ y.delete(i), m();
244
+ }, r = (n) => {
245
+ 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);
248
+ if (f) return f.promise.then(T);
249
+ let a = () => {
240
250
  };
241
- const h = new Promise((v) => {
242
- f = v;
243
- }).then(() => e.request(r));
244
- return d.set(t, { promise: h, release: f }), h;
251
+ const p = new Promise((A) => {
252
+ a = A;
253
+ }).then(() => t.request(n));
254
+ return d.set(l, { promise: p, release: a }), y.add(i), p;
245
255
  };
246
- return new Proxy(e, {
247
- get(r, n, t) {
248
- if (n === "request") return l;
249
- if (n === "open") return s;
250
- if (n === "setOpen")
251
- return (f) => {
256
+ return new Proxy(t, {
257
+ get(n, e, l) {
258
+ if (e === "request") return r;
259
+ if (e === "open") return o;
260
+ if (e === "setOpen")
261
+ return (a) => {
252
262
  u !== void 0 && (clearTimeout(u), u = void 0);
253
- const c = s;
254
- s = f, f && !c && m();
263
+ const h = o;
264
+ o = a, a && !h && (y.delete(i), m());
255
265
  };
256
- if (n === "dispose")
266
+ if (e === "dispose")
257
267
  return () => {
258
268
  u === void 0 && (u = setTimeout(() => {
259
- u = void 0, s = !0, m();
269
+ u = void 0, o = !0, y.delete(i), m();
260
270
  }, 0));
261
271
  };
262
- const i = Reflect.get(r, n, t);
263
- return typeof i == "function" ? i.bind(r) : i;
272
+ const f = Reflect.get(n, e, l);
273
+ return typeof f == "function" ? f.bind(n) : f;
264
274
  }
265
275
  });
266
276
  }
267
277
  export {
268
278
  C as BATCH_READ_LIMIT,
269
- S as COLLECTION_BATCH_LIMIT,
270
- Z as COLLECTION_BATCH_WINDOW_MS,
271
- b as SETTLED_READ_MS,
279
+ O as COLLECTION_BATCH_LIMIT,
280
+ x as COLLECTION_BATCH_WINDOW_MS,
281
+ R as SETTLED_READ_MS,
272
282
  U as batchableCollectionMeta,
273
283
  $ as batchableRead,
274
- X as createGatedClient,
275
- O as forgetSettledReads,
276
- j as isCoalesced,
277
- Y as isSettledRead,
278
- V as withGetCoalescing
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
279
291
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",