@nivaro/react 0.3.4 → 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.
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +31 -0
- package/dist/index.js +288 -286
- package/dist/shared/context.js +96 -84
- package/dist/shared/lib/request-gate.js +190 -178
- package/package.json +1 -1
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { noteOwnWriteFromCommand as
|
|
2
|
-
function
|
|
3
|
-
if (!
|
|
4
|
-
const
|
|
5
|
-
return
|
|
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(
|
|
8
|
-
const
|
|
9
|
-
return `${
|
|
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
|
|
12
|
-
return (
|
|
11
|
+
function g(t) {
|
|
12
|
+
return (t._method ?? "GET").toUpperCase() === "GET";
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
function
|
|
16
|
-
return
|
|
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
|
|
19
|
-
if (
|
|
18
|
+
function T(t) {
|
|
19
|
+
if (t == null || typeof t != "object") return t;
|
|
20
20
|
try {
|
|
21
|
-
return structuredClone(
|
|
21
|
+
return structuredClone(t);
|
|
22
22
|
} catch {
|
|
23
|
-
return
|
|
23
|
+
return t;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
function
|
|
28
|
-
return
|
|
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 $(
|
|
44
|
-
const
|
|
45
|
-
if ((
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
const [, u, d] =
|
|
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 =
|
|
51
|
-
for (const [
|
|
52
|
-
if (
|
|
53
|
-
if (!M.has(
|
|
54
|
-
|
|
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:
|
|
56
|
+
return d === void 0 ? { collection: u, query: i } : { collection: u, id: d, query: i };
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
let
|
|
60
|
-
const u = (
|
|
61
|
-
if (
|
|
62
|
-
let
|
|
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
|
|
64
|
+
const c = await t.request({
|
|
65
65
|
_method: "POST",
|
|
66
66
|
_path: "/items/batch-read",
|
|
67
67
|
_body: {
|
|
68
|
-
reads:
|
|
69
|
-
key: String(
|
|
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
|
-
|
|
76
|
+
r = Array.isArray(c == null ? void 0 : c.results) ? c.results : void 0;
|
|
77
77
|
} catch {
|
|
78
|
-
|
|
78
|
+
r = void 0;
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
if ((
|
|
83
|
-
u(
|
|
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
|
-
|
|
86
|
+
c.resolve(c.read.id !== void 0 ? { data: e.data } : { data: e.data, ...e.meta ?? {} });
|
|
87
87
|
});
|
|
88
88
|
}, m = () => {
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
for (let
|
|
93
|
-
d(
|
|
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 (
|
|
96
|
-
|
|
97
|
-
read:
|
|
98
|
-
command:
|
|
99
|
-
resolve:
|
|
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
|
-
}),
|
|
101
|
+
}), o === void 0 && (o = setTimeout(m, 0));
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
|
-
const
|
|
105
|
-
function U(
|
|
106
|
-
const
|
|
107
|
-
if ((
|
|
108
|
-
const
|
|
109
|
-
return
|
|
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
|
|
115
|
-
let
|
|
116
|
-
const d = (
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
for (const
|
|
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
|
|
124
|
+
n = await t.request({
|
|
125
125
|
_method: "GET",
|
|
126
126
|
_path: "/collections",
|
|
127
|
-
_params: { names:
|
|
127
|
+
_params: { names: c.join(",") }
|
|
128
128
|
});
|
|
129
|
-
} catch (
|
|
130
|
-
const h =
|
|
131
|
-
if (h === 400 || h === 404 || h === 405)
|
|
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
|
|
133
|
+
for (const p of r) p.reject(a);
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
136
|
n = void 0;
|
|
137
137
|
}
|
|
138
|
-
const
|
|
139
|
-
if (!
|
|
140
|
-
Array.isArray(
|
|
141
|
-
for (const
|
|
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
|
|
145
|
-
for (const
|
|
146
|
-
Object.hasOwn(
|
|
147
|
-
},
|
|
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
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
for (const
|
|
153
|
-
let
|
|
154
|
-
if (!
|
|
155
|
-
const f =
|
|
156
|
-
|
|
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
|
-
|
|
158
|
+
l.push(e);
|
|
159
159
|
}
|
|
160
|
-
for (const
|
|
160
|
+
for (const e of c) m(e);
|
|
161
161
|
};
|
|
162
|
-
return (
|
|
163
|
-
|
|
164
|
-
name:
|
|
165
|
-
command:
|
|
162
|
+
return (r, c) => new Promise((n, e) => {
|
|
163
|
+
o.push({
|
|
164
|
+
name: c,
|
|
165
|
+
command: r,
|
|
166
166
|
resolve: n,
|
|
167
|
-
reject:
|
|
168
|
-
}), u === void 0 && (u = setTimeout(
|
|
167
|
+
reject: e
|
|
168
|
+
}), u === void 0 && (u = setTimeout(i, x));
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
|
-
const
|
|
172
|
-
function
|
|
173
|
-
const
|
|
174
|
-
return (
|
|
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
|
|
177
|
-
const
|
|
178
|
-
if (!
|
|
179
|
-
const
|
|
180
|
-
return !(
|
|
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
|
|
183
|
-
function
|
|
184
|
-
|
|
182
|
+
let v = 0;
|
|
183
|
+
function G() {
|
|
184
|
+
v++;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
if (
|
|
188
|
-
const
|
|
189
|
-
let
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
|
|
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 [
|
|
195
|
-
m.set(n, { at: f, epoch:
|
|
196
|
-
},
|
|
197
|
-
const
|
|
198
|
-
if (!
|
|
199
|
-
|
|
200
|
-
const _ = !
|
|
201
|
-
_ &&
|
|
202
|
-
const
|
|
203
|
-
return (_ ?
|
|
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
|
|
205
|
+
const l = k(e), f = J(e);
|
|
206
206
|
if (f) {
|
|
207
|
-
const _ = m.get(
|
|
208
|
-
if (_ && _.epoch ===
|
|
209
|
-
return Promise.resolve(
|
|
207
|
+
const _ = m.get(l);
|
|
208
|
+
if (_ && _.epoch === v && Date.now() - _.at < R)
|
|
209
|
+
return Promise.resolve(T(_.value));
|
|
210
210
|
}
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
const h = u ? $(
|
|
214
|
-
|
|
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
|
|
216
|
+
return o.set(l, E), E;
|
|
217
217
|
};
|
|
218
|
-
return new Proxy(
|
|
219
|
-
get(n,
|
|
220
|
-
if (
|
|
221
|
-
if (
|
|
222
|
-
const f = Reflect.get(n,
|
|
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
|
|
228
|
-
function
|
|
229
|
-
|
|
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
|
|
239
|
+
const n = [...d.values()];
|
|
232
240
|
d.clear();
|
|
233
|
-
for (const
|
|
234
|
-
},
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
if (
|
|
239
|
-
|
|
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
|
|
242
|
-
|
|
243
|
-
}).then(() =>
|
|
244
|
-
return d.set(
|
|
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(
|
|
247
|
-
get(
|
|
248
|
-
if (
|
|
249
|
-
if (
|
|
250
|
-
if (
|
|
251
|
-
return (
|
|
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
|
|
254
|
-
|
|
263
|
+
const h = o;
|
|
264
|
+
o = a, a && !h && (y.delete(i), m());
|
|
255
265
|
};
|
|
256
|
-
if (
|
|
266
|
+
if (e === "dispose")
|
|
257
267
|
return () => {
|
|
258
268
|
u === void 0 && (u = setTimeout(() => {
|
|
259
|
-
u = void 0,
|
|
269
|
+
u = void 0, o = !0, y.delete(i), m();
|
|
260
270
|
}, 0));
|
|
261
271
|
};
|
|
262
|
-
const
|
|
263
|
-
return typeof
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
V as
|
|
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
|
};
|