@gemologic/sheen-table 0.3.0 → 0.4.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.
- package/dist/DataTable.d.ts +57 -13
- package/dist/DataTable.js +963 -820
- package/dist/FilterBar.d.ts +3 -3
- package/dist/FilterBar.js +5 -1
- package/dist/client-state.d.ts +9 -3
- package/dist/client-state.js +38 -32
- package/dist/core.d.ts +5 -5
- package/dist/core.js +28 -28
- package/dist/data-table-features.d.ts +18 -13
- package/dist/data-table-features.js +11 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +32 -31
- package/dist/messages.d.ts +3 -0
- package/dist/messages.js +3 -0
- package/dist/pagination.d.ts +43 -1
- package/dist/pagination.js +109 -54
- package/dist/requests.d.ts +3 -3
- package/dist/requests.js +38 -28
- package/dist/saved-views.d.ts +17 -14
- package/dist/saved-views.js +71 -68
- package/dist/server-export.d.ts +16 -7
- package/dist/server-export.js +57 -53
- package/dist/table-state-changes.d.ts +6 -3
- package/dist/table-state-changes.js +44 -40
- package/dist/table-state.d.ts +20 -4
- package/dist/table-state.js +66 -40
- package/dist/url-state.d.ts +12 -9
- package/dist/url-state.js +33 -30
- package/package.json +3 -3
- package/src/DataTable.tsx +221 -61
- package/src/FilterBar.tsx +5 -3
- package/src/client-state.ts +31 -17
- package/src/core.ts +5 -5
- package/src/data-table-features.tsx +23 -10
- package/src/index.ts +5 -3
- package/src/messages.ts +1 -1
- package/src/pagination.ts +83 -14
- package/src/requests.ts +22 -8
- package/src/saved-views.ts +33 -11
- package/src/server-export.ts +17 -11
- package/src/table-state-changes.ts +22 -12
- package/src/table-state.ts +53 -11
- package/src/url-state.ts +27 -10
package/dist/pagination.js
CHANGED
|
@@ -1,101 +1,156 @@
|
|
|
1
1
|
// src/pagination.ts
|
|
2
|
-
|
|
2
|
+
var e = "Server mode requires explicit pagination, including explicit false for complete results";
|
|
3
|
+
function t(e, t) {
|
|
3
4
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw Error(`${t} must be a nonnegative safe integer`);
|
|
4
5
|
}
|
|
5
|
-
function
|
|
6
|
-
if (t ===
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
function n(e) {
|
|
7
|
+
if (t(e, "pageSize"), e === 0) throw Error("pageSize must be positive");
|
|
8
|
+
return e;
|
|
9
|
+
}
|
|
10
|
+
function r(e, t) {
|
|
11
|
+
if (Object.keys(e).some((e) => !t.includes(e))) throw Error("pagination contains unknown fields");
|
|
12
|
+
}
|
|
13
|
+
function i(e, t) {
|
|
14
|
+
if (typeof e != "string" || !e) throw Error(`${t} must be a nonempty string or null`);
|
|
15
|
+
return e;
|
|
16
|
+
}
|
|
17
|
+
function a(e) {
|
|
18
|
+
if (e === !1) return !1;
|
|
19
|
+
if (typeof e != "object" || !e || Array.isArray(e) || !("pageIndex" in e) || !("pageSize" in e)) throw Error("pagination must be false or { pageIndex, pageSize }");
|
|
20
|
+
return r(e, ["pageIndex", "pageSize"]), t(e.pageIndex, "pageIndex"), Object.freeze({
|
|
21
|
+
pageIndex: e.pageIndex,
|
|
22
|
+
pageSize: n(e.pageSize)
|
|
13
23
|
});
|
|
14
24
|
}
|
|
15
|
-
function
|
|
16
|
-
if (
|
|
25
|
+
function o(t, n) {
|
|
26
|
+
if (t !== "client" && t !== "server") throw Error("Table mode must be client or server");
|
|
17
27
|
if (n === void 0) {
|
|
18
|
-
if (
|
|
28
|
+
if (t === "server") throw Error(e);
|
|
19
29
|
return !1;
|
|
20
30
|
}
|
|
21
|
-
return
|
|
31
|
+
return a(n);
|
|
22
32
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
function s(e) {
|
|
34
|
+
if (typeof e != "object" || !e || Array.isArray(e) || !("kind" in e) || e.kind !== "cursor" || !("pageSize" in e) || !("cursor" in e)) throw Error("cursor pagination must be { kind: \"cursor\", pageSize, cursor }");
|
|
35
|
+
r(e, [
|
|
36
|
+
"kind",
|
|
37
|
+
"pageSize",
|
|
38
|
+
"cursor"
|
|
39
|
+
]);
|
|
40
|
+
let t = e.cursor;
|
|
41
|
+
if (t === null) return Object.freeze({
|
|
42
|
+
kind: "cursor",
|
|
43
|
+
pageSize: n(e.pageSize),
|
|
44
|
+
cursor: null
|
|
45
|
+
});
|
|
46
|
+
if (typeof t != "object" || !("direction" in t) || !("value" in t) || t.direction !== "after" && t.direction !== "before") throw Error("cursor must be null or { direction: after | before, value }");
|
|
47
|
+
return r(t, ["direction", "value"]), Object.freeze({
|
|
48
|
+
kind: "cursor",
|
|
49
|
+
pageSize: n(e.pageSize),
|
|
50
|
+
cursor: Object.freeze({
|
|
51
|
+
direction: t.direction,
|
|
52
|
+
value: i(t.value, "cursor value")
|
|
53
|
+
})
|
|
28
54
|
});
|
|
29
55
|
}
|
|
30
|
-
function
|
|
31
|
-
if (t
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
function c(t) {
|
|
57
|
+
if (t === void 0) throw Error(e);
|
|
58
|
+
return typeof t == "object" && t && "kind" in t ? s(t) : a(t);
|
|
59
|
+
}
|
|
60
|
+
function l(e) {
|
|
61
|
+
let t = c(e);
|
|
62
|
+
return t !== !1 && u(t, t.pageSize);
|
|
63
|
+
}
|
|
64
|
+
function u(e, t) {
|
|
65
|
+
let r = c(e);
|
|
66
|
+
if (r === !1) throw Error("Page-size changes require paginated state");
|
|
67
|
+
return "kind" in r ? Object.freeze({
|
|
68
|
+
kind: "cursor",
|
|
69
|
+
pageSize: n(t),
|
|
70
|
+
cursor: null
|
|
71
|
+
}) : Object.freeze({
|
|
34
72
|
pageIndex: 0,
|
|
35
|
-
pageSize:
|
|
73
|
+
pageSize: n(t)
|
|
36
74
|
});
|
|
37
75
|
}
|
|
38
|
-
function
|
|
39
|
-
let
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
let
|
|
76
|
+
function d(e, n) {
|
|
77
|
+
let r = a(e);
|
|
78
|
+
if (r === !1) throw Error("Page ranges require paginated state");
|
|
79
|
+
t(n, "total");
|
|
80
|
+
let i = Math.ceil(n / r.pageSize), o = Math.min(r.pageIndex, Math.max(0, i - 1)), s = o * r.pageSize, c = s + Math.min(r.pageSize, n - s);
|
|
43
81
|
return Object.freeze({
|
|
44
82
|
pageIndex: o,
|
|
45
|
-
pageSize:
|
|
46
|
-
pageCount:
|
|
83
|
+
pageSize: r.pageSize,
|
|
84
|
+
pageCount: i,
|
|
47
85
|
start: s,
|
|
48
86
|
end: c
|
|
49
87
|
});
|
|
50
88
|
}
|
|
51
|
-
function
|
|
52
|
-
let
|
|
53
|
-
if (
|
|
89
|
+
function f(e, t = !1) {
|
|
90
|
+
let n = a(t);
|
|
91
|
+
if (n === !1) return {
|
|
54
92
|
rows: e,
|
|
55
93
|
total: e.length,
|
|
56
94
|
pagination: !1
|
|
57
95
|
};
|
|
58
|
-
let
|
|
96
|
+
let r = d(n, e.length);
|
|
59
97
|
return {
|
|
60
|
-
rows: e.slice(
|
|
98
|
+
rows: e.slice(r.start, r.end),
|
|
61
99
|
total: e.length,
|
|
62
100
|
pagination: Object.freeze({
|
|
63
|
-
pageIndex:
|
|
64
|
-
pageSize:
|
|
101
|
+
pageIndex: r.pageIndex,
|
|
102
|
+
pageSize: r.pageSize
|
|
65
103
|
})
|
|
66
104
|
};
|
|
67
105
|
}
|
|
68
|
-
function
|
|
69
|
-
let
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
106
|
+
function p(e, n) {
|
|
107
|
+
let r = a(e);
|
|
108
|
+
if (t(n.total, "total"), !Array.isArray(n.rows)) throw Error("Server rows must be an array");
|
|
109
|
+
if (r === !1) {
|
|
110
|
+
if (n.rows.length !== n.total) throw Error("Non-paginated server results must be complete: rows.length must equal total");
|
|
73
111
|
return {
|
|
74
112
|
kind: "accepted",
|
|
75
113
|
pagination: !1,
|
|
76
|
-
result:
|
|
114
|
+
result: n
|
|
77
115
|
};
|
|
78
116
|
}
|
|
79
|
-
let
|
|
80
|
-
if (
|
|
81
|
-
if (
|
|
117
|
+
let i = d(r, n.total);
|
|
118
|
+
if (i.pageIndex !== r.pageIndex && n.total > 0) {
|
|
119
|
+
if (n.rows.length) throw Error("Out-of-range server page must not contain rows");
|
|
82
120
|
return {
|
|
83
121
|
kind: "refetch",
|
|
84
122
|
pagination: Object.freeze({
|
|
85
|
-
pageIndex:
|
|
86
|
-
pageSize:
|
|
123
|
+
pageIndex: i.pageIndex,
|
|
124
|
+
pageSize: i.pageSize
|
|
87
125
|
}),
|
|
88
|
-
total:
|
|
126
|
+
total: n.total
|
|
89
127
|
};
|
|
90
128
|
}
|
|
91
|
-
if (
|
|
129
|
+
if (n.rows.length !== i.end - i.start) throw Error("Server page row count does not match the requested page and total");
|
|
92
130
|
return {
|
|
93
131
|
kind: "accepted",
|
|
94
132
|
pagination: Object.freeze({
|
|
95
|
-
pageIndex:
|
|
96
|
-
pageSize:
|
|
133
|
+
pageIndex: i.pageIndex,
|
|
134
|
+
pageSize: i.pageSize
|
|
97
135
|
}),
|
|
98
|
-
result:
|
|
136
|
+
result: n
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function m(e, n) {
|
|
140
|
+
let r = s(e);
|
|
141
|
+
if (!Array.isArray(n.rows)) throw Error("Server rows must be an array");
|
|
142
|
+
if (n.rows.length > r.pageSize) throw Error("Cursor page contains more rows than pageSize");
|
|
143
|
+
if (n.nextCursor !== null && i(n.nextCursor, "nextCursor"), n.previousCursor !== null && i(n.previousCursor, "previousCursor"), n.total !== void 0) {
|
|
144
|
+
if (typeof n.total != "object" || n.total === null || n.total.kind !== "exact" && n.total.kind !== "estimate" && n.total.kind !== "atLeast") throw Error("Cursor total must be { kind: exact | estimate | atLeast, value }");
|
|
145
|
+
t(n.total.value, "total value");
|
|
146
|
+
}
|
|
147
|
+
return n.rows.length === 0 && r.cursor !== null ? {
|
|
148
|
+
kind: "refetch",
|
|
149
|
+
pagination: l(r)
|
|
150
|
+
} : {
|
|
151
|
+
kind: "accepted",
|
|
152
|
+
pagination: r,
|
|
153
|
+
result: n
|
|
99
154
|
};
|
|
100
155
|
}
|
|
101
|
-
export {
|
|
156
|
+
export { m as assessCursorPage, p as assessServerPage, d as getPageRange, f as paginateClientRows, s as parseCursorPagination, a as parsePagination, c as parseServerPagination, l as resetPagination, u as resizePagination, o as resolvePagination };
|
package/dist/requests.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PageResult,
|
|
1
|
+
import type { CursorPageResult, PageResult, ServerPagination } from "./pagination.ts";
|
|
2
2
|
export interface TableRequestState {
|
|
3
|
-
readonly pagination:
|
|
3
|
+
readonly pagination: ServerPagination;
|
|
4
4
|
}
|
|
5
5
|
export interface TableRequestSnapshot<State, Result> {
|
|
6
6
|
readonly accepted: {
|
|
@@ -17,7 +17,7 @@ export interface InitialTableResult<State, Result> {
|
|
|
17
17
|
readonly result: Result;
|
|
18
18
|
}
|
|
19
19
|
/** Framework-neutral request ownership. Read snapshots before/after awaiting request in the UI adapter. */
|
|
20
|
-
export declare function createTableRequests<State extends TableRequestState, Result extends PageResult<unknown>>(onStateChange: (state: State, signal: AbortSignal) => Promise<Result>, initial?: InitialTableResult<State, Result>): {
|
|
20
|
+
export declare function createTableRequests<State extends TableRequestState, Result extends PageResult<unknown> | CursorPageResult<unknown>>(onStateChange: (state: State, signal: AbortSignal) => Promise<Result>, initial?: InitialTableResult<State, Result>): {
|
|
21
21
|
getSnapshot: () => TableRequestSnapshot<State, Result>;
|
|
22
22
|
request: (value: State) => Promise<TableRequestOutcome>;
|
|
23
23
|
retry: () => Promise<TableRequestOutcome>;
|
package/dist/requests.js
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assessCursorPage as e, assessServerPage as t, parseServerPagination as n } from "./pagination.js";
|
|
2
2
|
// src/requests.ts
|
|
3
|
-
function
|
|
4
|
-
|
|
3
|
+
function r(e) {
|
|
4
|
+
return "nextCursor" in e && "previousCursor" in e;
|
|
5
|
+
}
|
|
6
|
+
function i(i, a) {
|
|
7
|
+
let o = n(i);
|
|
8
|
+
if (o !== !1 && "kind" in o) {
|
|
9
|
+
if (!r(a)) throw Error("Cursor pagination results require nextCursor and previousCursor");
|
|
10
|
+
return e(o, a);
|
|
11
|
+
}
|
|
12
|
+
if (r(a)) throw Error("Numbered and complete server results must report total instead of cursors");
|
|
13
|
+
return t(o, a);
|
|
14
|
+
}
|
|
15
|
+
function a(e, t) {
|
|
16
|
+
let r = {
|
|
5
17
|
accepted: null,
|
|
6
18
|
requested: null,
|
|
7
19
|
pending: !1,
|
|
8
20
|
error: null
|
|
9
21
|
};
|
|
10
|
-
if (
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (a.kind !== "accepted") throw Error("Initial table results must describe a valid accepted page, not a page requiring refetch");
|
|
15
|
-
i = {
|
|
22
|
+
if (t) {
|
|
23
|
+
let e = structuredClone(t.state), n = i(e.pagination, t.result);
|
|
24
|
+
if (n.kind !== "accepted") throw Error("Initial table results must describe a valid accepted page, not a page requiring refetch");
|
|
25
|
+
r = {
|
|
16
26
|
accepted: {
|
|
17
27
|
state: {
|
|
18
|
-
...
|
|
19
|
-
pagination:
|
|
28
|
+
...e,
|
|
29
|
+
pagination: n.pagination
|
|
20
30
|
},
|
|
21
|
-
result:
|
|
31
|
+
result: t.result
|
|
22
32
|
},
|
|
23
33
|
requested: null,
|
|
24
34
|
pending: !1,
|
|
@@ -26,36 +36,36 @@ function n(n, r) {
|
|
|
26
36
|
};
|
|
27
37
|
}
|
|
28
38
|
let a = 0n, o, s = !1, c = !1;
|
|
29
|
-
async function l(
|
|
39
|
+
async function l(t) {
|
|
30
40
|
if (s) return "disposed";
|
|
31
41
|
if (c) return "superseded";
|
|
32
42
|
let l = ++a;
|
|
33
43
|
if (o?.abort(), s) return "disposed";
|
|
34
44
|
if (l !== a) return "superseded";
|
|
35
45
|
let u = new AbortController();
|
|
36
|
-
o = u,
|
|
37
|
-
...
|
|
46
|
+
o = u, r = {
|
|
47
|
+
...r,
|
|
38
48
|
requested: null,
|
|
39
49
|
pending: !0,
|
|
40
50
|
error: null
|
|
41
51
|
};
|
|
42
52
|
try {
|
|
43
|
-
let o = structuredClone(
|
|
44
|
-
|
|
45
|
-
...
|
|
53
|
+
let o = structuredClone(t);
|
|
54
|
+
n(o.pagination), r = {
|
|
55
|
+
...r,
|
|
46
56
|
requested: structuredClone(o),
|
|
47
57
|
pending: !0,
|
|
48
58
|
error: null
|
|
49
59
|
};
|
|
50
60
|
for (let t = 0; t < 4; t++) {
|
|
51
|
-
let t = await
|
|
61
|
+
let t = await e(structuredClone(o), u.signal);
|
|
52
62
|
if (s) return "disposed";
|
|
53
63
|
if (l !== a) return "superseded";
|
|
54
|
-
let
|
|
64
|
+
let n = i(o.pagination, t);
|
|
55
65
|
if (o = {
|
|
56
66
|
...o,
|
|
57
|
-
pagination:
|
|
58
|
-
},
|
|
67
|
+
pagination: n.pagination
|
|
68
|
+
}, n.kind === "accepted") return r = {
|
|
59
69
|
accepted: {
|
|
60
70
|
state: o,
|
|
61
71
|
result: t
|
|
@@ -67,8 +77,8 @@ function n(n, r) {
|
|
|
67
77
|
}
|
|
68
78
|
throw Error("Server page kept moving during clamping; retry the latest query");
|
|
69
79
|
} catch (e) {
|
|
70
|
-
return s ? "disposed" : l === a ? (
|
|
71
|
-
...
|
|
80
|
+
return s ? "disposed" : l === a ? (r = {
|
|
81
|
+
...r,
|
|
72
82
|
pending: !1,
|
|
73
83
|
error: e
|
|
74
84
|
}, "failed") : "superseded";
|
|
@@ -80,7 +90,7 @@ function n(n, r) {
|
|
|
80
90
|
if (c) return;
|
|
81
91
|
c = !0, a++;
|
|
82
92
|
let e = o;
|
|
83
|
-
o = void 0,
|
|
93
|
+
o = void 0, r = {
|
|
84
94
|
accepted: null,
|
|
85
95
|
requested: null,
|
|
86
96
|
pending: !1,
|
|
@@ -93,13 +103,13 @@ function n(n, r) {
|
|
|
93
103
|
}
|
|
94
104
|
}
|
|
95
105
|
return {
|
|
96
|
-
getSnapshot: () =>
|
|
106
|
+
getSnapshot: () => r,
|
|
97
107
|
request: l,
|
|
98
|
-
retry: () =>
|
|
108
|
+
retry: () => r.requested ? l(r.requested) : Promise.resolve(s ? "disposed" : "failed"),
|
|
99
109
|
clear: u,
|
|
100
110
|
dispose: () => {
|
|
101
111
|
s = !0, u();
|
|
102
112
|
}
|
|
103
113
|
};
|
|
104
114
|
}
|
|
105
|
-
export {
|
|
115
|
+
export { a as createTableRequests };
|
package/dist/saved-views.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CursorPagination, ServerPagination, TablePagination } from "./pagination.ts";
|
|
2
|
+
import type { CursorTableStateSchema, TableState, TableStateSchema } from "./table-state.ts";
|
|
2
3
|
export interface SavedViewRecord {
|
|
3
4
|
readonly id: string;
|
|
4
5
|
readonly name: string;
|
|
@@ -30,23 +31,25 @@ export interface SavedViewsSnapshot {
|
|
|
30
31
|
readonly error: unknown;
|
|
31
32
|
}
|
|
32
33
|
export type SavedViewOutcome = "accepted" | "failed" | "superseded" | "disposed";
|
|
33
|
-
export type SavedViewRestore = {
|
|
34
|
+
export type SavedViewRestore<Pagination extends ServerPagination = TablePagination> = {
|
|
34
35
|
readonly kind: "accepted";
|
|
35
|
-
readonly state: TableState
|
|
36
|
+
readonly state: TableState<Pagination>;
|
|
36
37
|
} | {
|
|
37
38
|
readonly kind: "missing";
|
|
38
39
|
} | {
|
|
39
40
|
readonly kind: "invalid";
|
|
40
41
|
readonly error: unknown;
|
|
41
42
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
export interface SavedViews<Pagination extends ServerPagination = TablePagination> {
|
|
44
|
+
readonly getSnapshot: () => SavedViewsSnapshot;
|
|
45
|
+
readonly list: () => Promise<SavedViewOutcome>;
|
|
46
|
+
readonly save: (name: string, state: TableState<Pagination>, id?: string | null) => Promise<SavedViewOutcome>;
|
|
47
|
+
readonly delete: (id: string) => Promise<SavedViewOutcome>;
|
|
48
|
+
readonly restore: (id: string) => SavedViewRestore<Pagination>;
|
|
49
|
+
readonly retry: () => Promise<SavedViewOutcome>;
|
|
50
|
+
readonly clear: () => void;
|
|
51
|
+
readonly dispose: () => void;
|
|
52
|
+
}
|
|
53
|
+
/** Async saved-view ownership. Persistence and authorization stay in the app adapter. Cursor schemas save and restore only the first page. */
|
|
54
|
+
export declare function createSavedViews(adapter: SavedViewsAdapter, schema: CursorTableStateSchema): SavedViews<CursorPagination>;
|
|
55
|
+
export declare function createSavedViews(adapter: SavedViewsAdapter, schema: TableStateSchema): SavedViews;
|
package/dist/saved-views.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { deserializeState as e,
|
|
1
|
+
import { deserializeState as e, schemaPagination as t, serializeState as n } from "./table-state.js";
|
|
2
2
|
// src/saved-views.ts
|
|
3
|
-
function
|
|
3
|
+
function r(e, t) {
|
|
4
4
|
if (typeof e != "string" || !e || e.trim() !== e) throw Error(`${t} must be a nonempty trimmed string`);
|
|
5
5
|
return e;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function i(e, t) {
|
|
8
8
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error(`${t} must be an object`);
|
|
9
|
-
let
|
|
10
|
-
if (
|
|
11
|
-
let i =
|
|
9
|
+
let n = Object.keys(e);
|
|
10
|
+
if (n.length !== 3 || !n.includes("id") || !n.includes("name") || !n.includes("state")) throw Error(`${t} must contain exactly id, name, and state`);
|
|
11
|
+
let i = r(e.id, `${t}.id`), a = r(e.name, `${t}.name`);
|
|
12
12
|
if (typeof e.state != "string" || !e.state) throw Error(`${t}.state must be a nonempty serialized string`);
|
|
13
13
|
return Object.freeze({
|
|
14
14
|
id: i,
|
|
@@ -16,99 +16,102 @@ function r(e, t) {
|
|
|
16
16
|
state: e.state
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function a(e) {
|
|
20
20
|
if (!Array.isArray(e)) throw Error("Saved view list must be an array");
|
|
21
|
-
let t = [], n = /* @__PURE__ */ new Set(),
|
|
21
|
+
let t = [], n = /* @__PURE__ */ new Set(), r = 0;
|
|
22
22
|
for (let a of e) {
|
|
23
|
-
let e =
|
|
24
|
-
if (n.has(e.id)) throw Error(`views[${
|
|
25
|
-
n.add(e.id), t.push(e),
|
|
23
|
+
let e = i(a, `views[${r}]`);
|
|
24
|
+
if (n.has(e.id)) throw Error(`views[${r}] duplicates ID ${e.id}`);
|
|
25
|
+
n.add(e.id), t.push(e), r++;
|
|
26
26
|
}
|
|
27
27
|
return Object.freeze(t);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function o(e) {
|
|
30
30
|
return e.kind === "save" ? Object.freeze({
|
|
31
31
|
kind: "save",
|
|
32
32
|
view: Object.freeze({ ...e.view })
|
|
33
33
|
}) : Object.freeze({ ...e });
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
35
|
+
function s(r, i) {
|
|
36
|
+
return t(i), i.pagination, c(r, (e) => n(e, i), (t) => e(t, i));
|
|
37
|
+
}
|
|
38
|
+
function c(e, t, n) {
|
|
39
|
+
let s = Object.freeze({
|
|
37
40
|
accepted: null,
|
|
38
41
|
pending: null,
|
|
39
42
|
failed: null,
|
|
40
43
|
error: null
|
|
41
|
-
}),
|
|
42
|
-
async function
|
|
43
|
-
if (
|
|
44
|
-
if (
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
47
|
-
if (
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
...
|
|
51
|
-
pending:
|
|
44
|
+
}), c = 0n, l, u = !1, d = !1;
|
|
45
|
+
async function f(t) {
|
|
46
|
+
if (u) return "disposed";
|
|
47
|
+
if (d) return "superseded";
|
|
48
|
+
let r = o(t), f = ++c, p = l;
|
|
49
|
+
if (l = void 0, p?.abort(), u) return "disposed";
|
|
50
|
+
if (f !== c) return "superseded";
|
|
51
|
+
let m = new AbortController();
|
|
52
|
+
l = m, s = Object.freeze({
|
|
53
|
+
...s,
|
|
54
|
+
pending: r,
|
|
52
55
|
failed: null,
|
|
53
56
|
error: null
|
|
54
57
|
});
|
|
55
58
|
try {
|
|
56
|
-
if (
|
|
57
|
-
let
|
|
58
|
-
return
|
|
59
|
-
accepted:
|
|
59
|
+
if (r.kind === "list") {
|
|
60
|
+
let t = a(await e.list(m.signal));
|
|
61
|
+
return u ? "disposed" : f === c ? (s = Object.freeze({
|
|
62
|
+
accepted: t,
|
|
60
63
|
pending: null,
|
|
61
64
|
failed: null,
|
|
62
65
|
error: null
|
|
63
66
|
}), "accepted") : "superseded";
|
|
64
67
|
}
|
|
65
|
-
if (
|
|
66
|
-
let t =
|
|
67
|
-
if (
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
let
|
|
72
|
-
return
|
|
73
|
-
accepted: Object.freeze(
|
|
68
|
+
if (r.kind === "save") {
|
|
69
|
+
let t = i(await e.save(r.view, m.signal), "saved view");
|
|
70
|
+
if (u) return "disposed";
|
|
71
|
+
if (f !== c) return "superseded";
|
|
72
|
+
if (r.view.id !== null && r.view.id !== t.id) throw Error("Saved view adapter changed the requested ID");
|
|
73
|
+
n(t.state);
|
|
74
|
+
let a = s.accepted ?? [], o = a.findIndex((e) => e.id === t.id) < 0 ? [...a, t] : a.map((e) => e.id === t.id ? t : e);
|
|
75
|
+
return s = Object.freeze({
|
|
76
|
+
accepted: Object.freeze(o),
|
|
74
77
|
pending: null,
|
|
75
78
|
failed: null,
|
|
76
79
|
error: null
|
|
77
80
|
}), "accepted";
|
|
78
81
|
}
|
|
79
|
-
return await
|
|
80
|
-
accepted:
|
|
82
|
+
return await e.delete(r.id, m.signal), u ? "disposed" : f === c ? (s = Object.freeze({
|
|
83
|
+
accepted: s.accepted ? Object.freeze(s.accepted.filter((e) => e.id !== r.id)) : null,
|
|
81
84
|
pending: null,
|
|
82
85
|
failed: null,
|
|
83
86
|
error: null
|
|
84
87
|
}), "accepted") : "superseded";
|
|
85
88
|
} catch (e) {
|
|
86
|
-
return
|
|
87
|
-
...
|
|
89
|
+
return u ? "disposed" : f === c ? (s = Object.freeze({
|
|
90
|
+
...s,
|
|
88
91
|
pending: null,
|
|
89
|
-
failed:
|
|
92
|
+
failed: r,
|
|
90
93
|
error: e
|
|
91
94
|
}), "failed") : "superseded";
|
|
92
95
|
} finally {
|
|
93
|
-
|
|
96
|
+
f === c && (l = void 0);
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
|
-
function
|
|
97
|
-
return
|
|
99
|
+
function p(e, n, i = null) {
|
|
100
|
+
return f({
|
|
98
101
|
kind: "save",
|
|
99
102
|
view: Object.freeze({
|
|
100
|
-
id: i === null ? null :
|
|
101
|
-
name:
|
|
102
|
-
state: t(
|
|
103
|
+
id: i === null ? null : r(i, "Saved view ID"),
|
|
104
|
+
name: r(e, "Saved view name"),
|
|
105
|
+
state: t(n)
|
|
103
106
|
})
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
|
-
function
|
|
109
|
+
function m(e) {
|
|
107
110
|
try {
|
|
108
|
-
let
|
|
111
|
+
let t = r(e, "Saved view ID"), i = s.accepted?.find((e) => e.id === t);
|
|
109
112
|
return Object.freeze(i ? {
|
|
110
113
|
kind: "accepted",
|
|
111
|
-
state:
|
|
114
|
+
state: n(i.state)
|
|
112
115
|
} : { kind: "missing" });
|
|
113
116
|
} catch (e) {
|
|
114
117
|
return Object.freeze({
|
|
@@ -117,11 +120,11 @@ function o(o, s) {
|
|
|
117
120
|
});
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
|
-
function
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
let e =
|
|
124
|
-
|
|
123
|
+
function h() {
|
|
124
|
+
if (d) return;
|
|
125
|
+
d = !0, c++;
|
|
126
|
+
let e = l;
|
|
127
|
+
l = void 0, s = Object.freeze({
|
|
125
128
|
accepted: null,
|
|
126
129
|
pending: null,
|
|
127
130
|
failed: null,
|
|
@@ -130,23 +133,23 @@ function o(o, s) {
|
|
|
130
133
|
try {
|
|
131
134
|
e?.abort();
|
|
132
135
|
} finally {
|
|
133
|
-
|
|
136
|
+
d = !1;
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
return {
|
|
137
|
-
getSnapshot: () =>
|
|
138
|
-
list: () =>
|
|
139
|
-
save:
|
|
140
|
-
delete: (e) =>
|
|
140
|
+
getSnapshot: () => s,
|
|
141
|
+
list: () => f({ kind: "list" }),
|
|
142
|
+
save: p,
|
|
143
|
+
delete: (e) => f({
|
|
141
144
|
kind: "delete",
|
|
142
|
-
id:
|
|
145
|
+
id: r(e, "Saved view ID")
|
|
143
146
|
}),
|
|
144
|
-
restore:
|
|
145
|
-
retry: () =>
|
|
146
|
-
clear:
|
|
147
|
+
restore: m,
|
|
148
|
+
retry: () => s.failed ? f(s.failed) : Promise.resolve(u ? "disposed" : "failed"),
|
|
149
|
+
clear: h,
|
|
147
150
|
dispose() {
|
|
148
|
-
|
|
151
|
+
u = !0, h();
|
|
149
152
|
}
|
|
150
153
|
};
|
|
151
154
|
}
|
|
152
|
-
export {
|
|
155
|
+
export { s as createSavedViews };
|