@progress/kendo-react-data-tools 11.0.0-develop.8 → 11.0.0

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.
@@ -0,0 +1,496 @@
1
+ /**
2
+ * @license
3
+ *-------------------------------------------------------------------------------------------
4
+ * Copyright © 2025 Progress Software Corporation. All rights reserved.
5
+ * Licensed under commercial license. See LICENSE.md in the package root for more information
6
+ *-------------------------------------------------------------------------------------------
7
+ */
8
+ "use client";
9
+ import { validatePackage as Me, deepMerge as le, getter as ce, useImmediateInheritState as V, clone as ue } from "@progress/kendo-react-common";
10
+ import { useDataSource as Te } from "./use-data-source.mjs";
11
+ import { packageMetadata as be } from "../package-metadata.mjs";
12
+ const De = { data: (p) => p, total: (p) => p.length }, Se = {
13
+ create: {
14
+ method: "POST",
15
+ contentType: "application/json"
16
+ },
17
+ read: {
18
+ method: "GET"
19
+ },
20
+ update: {
21
+ method: "PUT",
22
+ contentType: "application/json"
23
+ },
24
+ delete: {
25
+ method: "DELETE"
26
+ }
27
+ }, B = (p, A) => {
28
+ const g = typeof p == "function" ? p(A) : p;
29
+ return new URL(g);
30
+ }, C = (p, A, g) => typeof p == "function" ? p(A) : g || p ? { ...g, ...p } : void 0, H = (p, A) => {
31
+ typeof A == "object" ? Object.keys(A).forEach((g) => {
32
+ p.searchParams.append(g, A[g]);
33
+ }) : typeof A == "string" && (p.search = A);
34
+ }, K = async ({
35
+ url: p,
36
+ method: A,
37
+ contentType: g,
38
+ body: Q,
39
+ onError: L,
40
+ onSuccess: W
41
+ }) => {
42
+ var i;
43
+ const N = await fetch(p, {
44
+ method: A,
45
+ headers: g ? { "Content-Type": g } : {},
46
+ ...Q ? { body: JSON.stringify(Q) } : {}
47
+ });
48
+ return N.ok ? W(
49
+ (i = N.headers.get("Content-Type")) != null && i.includes("application/json") ? await N.json() : await N.text()
50
+ ) : L == null ? void 0 : L(await N.json());
51
+ }, Ie = (p) => {
52
+ Me(be, { component: "useRemoteDataSource" });
53
+ const {
54
+ defaultTotal: A,
55
+ serverFiltering: g = !0,
56
+ serverSorting: Q = !0,
57
+ serverPaging: L = !0,
58
+ serverGrouping: W = !0,
59
+ ...N
60
+ } = p, i = le({}, De, p.schema), t = le(
61
+ {},
62
+ Se,
63
+ p.transport
64
+ ), de = typeof i.data == "function" ? i.data : i.data ? ce(i.data) : (a) => a, ie = typeof i.total == "function" ? i.total : i.total ? ce(i.total) : (a) => a, c = typeof (i == null ? void 0 : i.errors) == "function" ? (a) => i.errors(a) : i != null && i.errors ? ce(i == null ? void 0 : i.errors) : (a) => {
65
+ }, k = ce(String(i.model.id)), F = V(/* @__PURE__ */ new Map(), p.reads), D = V(/* @__PURE__ */ new Map(), p.creates), R = V(/* @__PURE__ */ new Map(), p.updates), x = V(/* @__PURE__ */ new Map(), p.deletes), w = V(/* @__PURE__ */ new Map()), S = V(/* @__PURE__ */ new Map()), ne = (a) => {
66
+ F.value = a;
67
+ }, X = (a) => {
68
+ D.value = a;
69
+ }, oe = (a) => {
70
+ R.value = a;
71
+ }, re = (a) => {
72
+ x.value = a;
73
+ }, q = (a) => {
74
+ w.value = a;
75
+ }, Y = (a) => {
76
+ S.value = a;
77
+ }, z = Te({
78
+ sortable: !Q,
79
+ pageable: !L,
80
+ filterable: !g,
81
+ groupable: !W,
82
+ get data() {
83
+ return Array.from(new Map([...D.value, ...F.value, ...R.value]).values()).filter(
84
+ (a) => !x.value.has(k(a))
85
+ );
86
+ },
87
+ ...N,
88
+ schema: i
89
+ }), se = (a) => {
90
+ const e = /* @__PURE__ */ new Map();
91
+ z.setData(a), a.forEach((n) => {
92
+ const o = k(n);
93
+ e.set(o, n);
94
+ }), ne(e);
95
+ }, O = (a) => {
96
+ const { error: e, data: n } = a;
97
+ if (!e)
98
+ return;
99
+ let o = null;
100
+ n && (o = k(n)), S.value.has(o) || S.value.set(o, []);
101
+ const s = S.value.get(o) || [];
102
+ s.push(e), S.value.set(o, s), Y(new Map(S.value));
103
+ }, ve = (a) => {
104
+ const { error: e } = a;
105
+ S.value.forEach((n, o) => {
106
+ const s = n.filter((f) => f !== e);
107
+ s.length === 0 ? S.value.delete(o) : S.value.set(o, s);
108
+ }), Y(new Map(S.value));
109
+ }, pe = (a) => {
110
+ const { data: e } = a, n = k(e);
111
+ S.value.delete(n), Y(new Map(S.value));
112
+ }, fe = () => {
113
+ S.value.clear(), Y(new Map(S.value));
114
+ }, we = (a) => {
115
+ const { data: e } = a, n = k(e);
116
+ D.value.set(n, e), X(new Map(D.value));
117
+ const o = new Set(Object.keys(e).filter((s) => {
118
+ var f;
119
+ return s !== ((f = i.model) == null ? void 0 : f.id);
120
+ }));
121
+ w.value.set(n, o), q(new Map(w.value));
122
+ }, ye = (a) => {
123
+ const { data: e, field: n } = a, o = k(e);
124
+ if (D.value.has(o)) {
125
+ const d = D.value.get(o);
126
+ D.value.set(o, { ...d, ...e }), X(new Map(D.value));
127
+ const r = w.value.get(o) || /* @__PURE__ */ new Set();
128
+ n ? r.add(n) : Object.keys(e).forEach((j) => {
129
+ var h;
130
+ j !== ((h = i.model) == null ? void 0 : h.id) && r.add(j);
131
+ }), w.value.set(o, r), q(new Map(w.value));
132
+ return;
133
+ }
134
+ const s = R.value.has(o) ? R.value.get(o) : F.value.has(o) ? F.value.get(o) : {};
135
+ R.value.set(o, { ...s, ...e }), oe(new Map(R.value));
136
+ const f = w.value.get(o) || /* @__PURE__ */ new Set();
137
+ n ? f.add(n) : Object.keys(e).forEach((d) => {
138
+ var r;
139
+ d !== ((r = i.model) == null ? void 0 : r.id) && f.add(d);
140
+ }), w.value.set(o, f), q(new Map(w.value));
141
+ }, me = (a) => {
142
+ const { data: e } = a, n = k(e);
143
+ if (D.value.has(n)) {
144
+ D.value.delete(n), X(new Map(D.value)), w.value.delete(n), q(new Map(w.value));
145
+ return;
146
+ }
147
+ x.value.set(n, e), re(new Map(x.value));
148
+ }, Z = (a) => {
149
+ const { data: e } = a, n = k(e);
150
+ D.value.delete(n), X(new Map(D.value)), w.value.delete(n), q(new Map(w.value));
151
+ }, $ = (a) => {
152
+ const { data: e, field: n } = a, o = k(e);
153
+ if (R.value.has(o))
154
+ if (n) {
155
+ const s = w.value.get(o);
156
+ s && (s.delete(n), s.size === 0 ? (R.value.delete(o), w.value.delete(o)) : w.value.set(o, s), oe(new Map(R.value)), q(new Map(w.value)));
157
+ } else
158
+ R.value.delete(o), oe(new Map(R.value)), w.value.delete(o), q(new Map(w.value));
159
+ }, E = (a) => {
160
+ const { data: e } = a, n = k(e);
161
+ x.value.delete(n), re(new Map(x.value)), w.value.delete(n), q(new Map(w.value));
162
+ }, ee = (a) => {
163
+ const { data: e } = a, n = k(e);
164
+ F.value.set(n, e), ne(new Map(F.value));
165
+ }, te = (a) => {
166
+ const { data: e } = a, n = k(e);
167
+ F.value.set(n, e), ne(new Map(F.value));
168
+ }, ae = (a) => {
169
+ const { data: e } = a, n = k(e);
170
+ F.value.delete(n), ne(new Map(F.value));
171
+ }, he = {
172
+ // CRUD collections
173
+ get reads() {
174
+ return F.value;
175
+ },
176
+ get creates() {
177
+ return D.value;
178
+ },
179
+ get updates() {
180
+ return R.value;
181
+ },
182
+ get deletes() {
183
+ return x.value;
184
+ },
185
+ get dirty() {
186
+ return w.value;
187
+ },
188
+ get errors() {
189
+ return S.value;
190
+ },
191
+ // CRUD operations
192
+ addError: O,
193
+ removeError: ve,
194
+ removeErrors: pe,
195
+ removeAllErrors: fe,
196
+ read: async (a) => {
197
+ var y, I, M, m, J, P, G;
198
+ if (!(t != null && t.read))
199
+ throw new Error("transport.read is not defined");
200
+ const e = (y = a == null ? void 0 : a.filter) != null ? y : z.filter, n = (I = a == null ? void 0 : a.skip) != null ? I : z.skip, o = (M = a == null ? void 0 : a.take) != null ? M : z.take, s = (m = a == null ? void 0 : a.sort) != null ? m : z.sort, f = (J = a == null ? void 0 : a.group) != null ? J : z.group;
201
+ if (typeof t.read == "function") {
202
+ const b = await t.read({
203
+ ...g && e !== void 0 && { filter: e },
204
+ ...L && n !== void 0 && { skip: n },
205
+ ...L && o !== void 0 && { take: o },
206
+ ...Q && s !== void 0 && { sort: s },
207
+ ...W && f !== void 0 && { group: f }
208
+ });
209
+ return se(b), b;
210
+ }
211
+ const d = {
212
+ ...g && e !== void 0 && { filter: e },
213
+ ...L && n !== void 0 && { skip: n },
214
+ ...L && o !== void 0 && { take: o },
215
+ ...Q && s !== void 0 && { sort: s },
216
+ ...W && f !== void 0 && { group: f }
217
+ }, r = B(t.read.url), j = t.read.onError, h = t.read.onResponse, _ = t.read.onSuccess, T = C(t.read.data), u = ((G = (P = t == null ? void 0 : t.read) == null ? void 0 : P.parameterMap) == null ? void 0 : G.call(P, { ...d, ...T })) || {
218
+ ...d,
219
+ ...T
220
+ };
221
+ H(r, u);
222
+ try {
223
+ const b = await K({
224
+ url: r,
225
+ method: t.read.method,
226
+ contentType: t.read.contentType,
227
+ body: T,
228
+ onError: async (l) => {
229
+ var U;
230
+ const v = (U = await (j == null ? void 0 : j(l))) != null ? U : c == null ? void 0 : c(l);
231
+ return v && O({ error: v }), [];
232
+ },
233
+ onSuccess: async (l) => {
234
+ var U;
235
+ const v = (U = await (h == null ? void 0 : h(l))) != null ? U : de(l);
236
+ return z.setTotal(await ie(l)), se(v), await (_ == null ? void 0 : _(v)), v;
237
+ }
238
+ });
239
+ return b != null ? b : [];
240
+ } catch (b) {
241
+ return console.error(b), [];
242
+ }
243
+ },
244
+ create: we,
245
+ update: ye,
246
+ delete: me,
247
+ // Renamed to "remove" internally to avoid JS keyword
248
+ sync: async () => {
249
+ await Promise.all(
250
+ Array.from(D.value).map(async ([a, e]) => {
251
+ var n, o, s, f;
252
+ if (t != null && t.create)
253
+ if (typeof t.create == "function")
254
+ try {
255
+ const d = await t.create({ data: e });
256
+ ee({ data: d || e }), Z({ data: e });
257
+ } catch (d) {
258
+ const r = c == null ? void 0 : c(d);
259
+ r && O({ error: r, data: e });
260
+ }
261
+ else {
262
+ const d = B(t.create.url, e), r = C(t.create.data, e, ue(e)), j = (f = (s = (o = (n = t == null ? void 0 : t.create) == null ? void 0 : n.parameterMap) == null ? void 0 : o.call(n, r)) != null ? s : r) != null ? f : {}, h = t.create.onError, _ = t.create.onResponse, T = t.create.onSuccess;
263
+ H(d, j);
264
+ try {
265
+ await K({
266
+ url: d,
267
+ method: t.create.method,
268
+ contentType: t.create.contentType,
269
+ body: r,
270
+ onError: async (u) => {
271
+ var I;
272
+ const y = (I = await (h == null ? void 0 : h(u))) != null ? I : c == null ? void 0 : c(u);
273
+ y && O({ error: y, data: e });
274
+ },
275
+ onSuccess: async (u) => {
276
+ const y = _ ? await _(u) : u;
277
+ ee({ data: y || e }), Z({ data: e }), await (T == null ? void 0 : T(y || e));
278
+ }
279
+ });
280
+ } catch (u) {
281
+ console.error(u);
282
+ }
283
+ }
284
+ })
285
+ ), await Promise.all(
286
+ Array.from(R.value).map(async ([a, e]) => {
287
+ var n, o, s, f;
288
+ if (t != null && t.update)
289
+ if (typeof t.update == "function")
290
+ try {
291
+ const d = await t.update({ data: e });
292
+ te({ data: d || e }), $({ data: e });
293
+ } catch (d) {
294
+ const r = c == null ? void 0 : c(d);
295
+ r && O({ error: r, data: e });
296
+ }
297
+ else {
298
+ const d = B(t.update.url, e), r = C(t.update.data, e, e), j = (f = (s = (o = (n = t == null ? void 0 : t.update) == null ? void 0 : n.parameterMap) == null ? void 0 : o.call(n, r)) != null ? s : r) != null ? f : {}, h = t.update.onError, _ = t.update.onResponse, T = t.update.onSuccess;
299
+ H(d, j);
300
+ try {
301
+ await K({
302
+ url: d,
303
+ method: t.update.method,
304
+ contentType: t.update.contentType,
305
+ body: r,
306
+ onError: async (u) => {
307
+ var I;
308
+ const y = (I = await (h == null ? void 0 : h(u))) != null ? I : c == null ? void 0 : c(u);
309
+ y && O({ error: y, data: e });
310
+ },
311
+ onSuccess: async (u) => {
312
+ const y = _ ? await _(u) : u;
313
+ return te({ data: y || e }), $({ data: e }), await (T == null ? void 0 : T(y || e)), y;
314
+ }
315
+ });
316
+ } catch (u) {
317
+ console.error(u);
318
+ }
319
+ }
320
+ })
321
+ ), await Promise.all(
322
+ Array.from(x.value).map(async ([a, e]) => {
323
+ var n, o, s, f;
324
+ if (t != null && t.delete)
325
+ if (typeof t.delete == "function")
326
+ try {
327
+ await t.delete({ data: e }), ae({ data: e }), E({ data: e });
328
+ } catch (d) {
329
+ const r = c == null ? void 0 : c(d);
330
+ r && O({ error: r, data: e });
331
+ }
332
+ else {
333
+ const d = B(t.delete.url, e), r = C(t.delete.data, e, e), j = (f = (s = (o = (n = t == null ? void 0 : t.delete) == null ? void 0 : n.parameterMap) == null ? void 0 : o.call(n, r)) != null ? s : r) != null ? f : {}, h = t.delete.onError, _ = t.delete.onResponse, T = t.delete.onSuccess;
334
+ H(d, j);
335
+ try {
336
+ await K({
337
+ url: d,
338
+ method: t.delete.method,
339
+ contentType: t.delete.contentType,
340
+ body: r,
341
+ onError: async (u) => {
342
+ var I;
343
+ const y = (I = await (h == null ? void 0 : h(u))) != null ? I : c == null ? void 0 : c(u);
344
+ y && O({ error: y, data: e });
345
+ },
346
+ onSuccess: async (u) => {
347
+ const y = _ ? await _(u) : u;
348
+ return ae({ data: Object.keys(y).length !== 0 ? y : e }), E({ data: e }), await (T == null ? void 0 : T(u || e)), u;
349
+ }
350
+ });
351
+ } catch (u) {
352
+ console.error(u);
353
+ }
354
+ }
355
+ })
356
+ );
357
+ },
358
+ syncItem: async (a) => {
359
+ var o, s, f, d, r, j, h, _, T, u, y, I;
360
+ const { data: e } = a, n = k(e);
361
+ if (D.value.has(n)) {
362
+ if (!(t != null && t.create))
363
+ return;
364
+ if (typeof t.create == "function")
365
+ try {
366
+ const M = await t.create({ data: e });
367
+ ee({ data: M || e }), Z({ data: e });
368
+ } catch (M) {
369
+ const m = c == null ? void 0 : c(M);
370
+ m && O({ error: m, data: e });
371
+ }
372
+ else {
373
+ const M = B(t.create.url, e), m = C(t.create.data, e, ue(e)), J = (d = (f = (s = (o = t == null ? void 0 : t.create) == null ? void 0 : o.parameterMap) == null ? void 0 : s.call(o, m)) != null ? f : m) != null ? d : {}, P = t.create.onError, G = t.create.onResponse, b = t.create.onSuccess;
374
+ H(M, J);
375
+ try {
376
+ await K({
377
+ url: M,
378
+ method: t.create.method,
379
+ contentType: t.create.contentType,
380
+ body: m,
381
+ onError: async (l) => {
382
+ var U;
383
+ const v = (U = await (P == null ? void 0 : P(l))) != null ? U : c == null ? void 0 : c(l);
384
+ v && O({ error: v, data: e });
385
+ },
386
+ onSuccess: async (l) => {
387
+ const v = G ? await G(l) : l;
388
+ return ee({ data: v || e }), Z({ data: e }), await (b == null ? void 0 : b(v || e)), v;
389
+ }
390
+ });
391
+ } catch (l) {
392
+ console.error(l);
393
+ }
394
+ }
395
+ }
396
+ if (R.value.has(n)) {
397
+ if (!(t != null && t.update))
398
+ return;
399
+ if (typeof t.update == "function")
400
+ try {
401
+ const M = await t.update({ data: e });
402
+ te({ data: M || e }), $({ data: e });
403
+ } catch (M) {
404
+ const m = c == null ? void 0 : c(M);
405
+ m && O({ error: m, data: e });
406
+ }
407
+ else {
408
+ const M = B(t.update.url, e), m = C(t.update.data, e, e), J = (_ = (h = (j = (r = t == null ? void 0 : t.update) == null ? void 0 : r.parameterMap) == null ? void 0 : j.call(r, m)) != null ? h : m) != null ? _ : {}, P = t.update.onError, G = t.update.onResponse, b = t.update.onSuccess;
409
+ H(M, J);
410
+ try {
411
+ await K({
412
+ url: M,
413
+ method: t.update.method,
414
+ contentType: t.update.contentType,
415
+ body: m,
416
+ onError: async (l) => {
417
+ var U;
418
+ const v = (U = await (P == null ? void 0 : P(l))) != null ? U : c == null ? void 0 : c(l);
419
+ v && O({ error: v, data: e });
420
+ },
421
+ onSuccess: async (l) => {
422
+ const v = G ? await G(l) : l;
423
+ return te({ data: v || e }), $({ data: e }), await (b == null ? void 0 : b(v || e)), v;
424
+ }
425
+ });
426
+ } catch (l) {
427
+ console.error(l);
428
+ }
429
+ }
430
+ }
431
+ if (x.value.has(n)) {
432
+ if (!(t != null && t.delete))
433
+ return;
434
+ if (typeof t.delete == "function")
435
+ try {
436
+ await t.delete({ data: e }), ae({ data: e }), E({ data: e });
437
+ } catch (M) {
438
+ const m = c == null ? void 0 : c(M);
439
+ m && O({ error: m, data: e });
440
+ }
441
+ else {
442
+ const M = B(t.delete.url, e), m = C(t.delete.data, e, e), J = (I = (y = (u = (T = t == null ? void 0 : t.delete) == null ? void 0 : T.parameterMap) == null ? void 0 : u.call(T, m)) != null ? y : m) != null ? I : {}, P = t.delete.onError, G = t.delete.onResponse, b = t.delete.onSuccess;
443
+ H(M, J);
444
+ try {
445
+ await K({
446
+ url: M,
447
+ method: t.delete.method,
448
+ contentType: t.delete.contentType,
449
+ body: m,
450
+ onError: async (l) => {
451
+ var U;
452
+ const v = (U = await (P == null ? void 0 : P(l))) != null ? U : c == null ? void 0 : c(l);
453
+ v && O({ error: v, data: e });
454
+ },
455
+ onSuccess: async (l) => {
456
+ const v = G ? await G(l) : l;
457
+ return ae({ data: v || e }), E({ data: e }), await (b == null ? void 0 : b(v || e)), l;
458
+ }
459
+ });
460
+ } catch (l) {
461
+ console.error(l);
462
+ }
463
+ }
464
+ }
465
+ },
466
+ removeCreate: Z,
467
+ removeUpdate: $,
468
+ removeDelete: E,
469
+ pushCreate: ee,
470
+ pushUpdate: te,
471
+ pushDelete: ae,
472
+ discard: () => {
473
+ D.value.clear(), X(new Map(D.value)), R.value.clear(), oe(new Map(R.value)), x.value.clear(), re(new Map(x.value)), w.value.clear(), q(new Map(w.value)), S.value.clear(), Y(new Map(S.value));
474
+ }
475
+ };
476
+ return Object.defineProperties(
477
+ {},
478
+ {
479
+ ...Object.getOwnPropertyDescriptors(z),
480
+ ...Object.fromEntries(
481
+ Object.entries(he).map(([a, e]) => [
482
+ a,
483
+ {
484
+ value: e,
485
+ writable: !0,
486
+ enumerable: !0,
487
+ configurable: !0
488
+ }
489
+ ])
490
+ )
491
+ }
492
+ );
493
+ };
494
+ export {
495
+ Ie as useRemoteDataSource
496
+ };