@marimo-team/islands 0.23.10-dev9 → 0.23.11-dev1
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/{ConnectedDataExplorerComponent-CyV83R2m.js → ConnectedDataExplorerComponent-Z3RP7Vmm.js} +31 -31
- package/dist/{ErrorBoundary-rULOrC_p.js → ErrorBoundary-DpbaKVv7.js} +1 -1
- package/dist/{any-language-editor-CiES2a2h.js → any-language-editor-CAgFD4Kd.js} +20 -20
- package/dist/assets/__vite-browser-external-eshhtsgZ.js +1 -0
- package/dist/assets/worker-CC0Oul9k.js +73 -0
- package/dist/{chat-ui-K84W5ecY.js → chat-ui-C4-GMW9y.js} +77 -77
- package/dist/{check-DTbrK0zt.js → check-BCaJeT-J.js} +1 -1
- package/dist/{chunk-5FQGJX7Z-BNjes6Yx.js → chunk-5FQGJX7Z-BbqSm5gU.js} +1227 -1222
- package/dist/{code-block-37QAKDTI-m92Yc8pv.js → code-block-37QAKDTI-O6IH6wAi.js} +1 -1
- package/dist/{code-visibility-v6ucEVUg.js → code-visibility-BDDI_K4x.js} +1943 -1223
- package/dist/{copy-5jQ_kGE1.js → copy-UqRYxiOg.js} +1 -1
- package/dist/dist-7QfXoMdB.js +5 -0
- package/dist/{dist-DgnE8F-r.js → dist-A2846XWO.js} +1 -1
- package/dist/dist-BEXXyZig.js +5 -0
- package/dist/{dist-B3pZ0Ab6.js → dist-BR_gyG9L.js} +3 -3
- package/dist/{dist-CcXxepx6.js → dist-BSAt6RhH.js} +27 -27
- package/dist/{dist-Bde4a2kU.js → dist-BY018Paw.js} +8 -8
- package/dist/dist-BYj57OV4.js +5 -0
- package/dist/{dist-CUCNs1ja.js → dist-BaoDKvdy.js} +2 -2
- package/dist/{dist-Cy1WxgBD.js → dist-Bf7SHuNp.js} +5 -5
- package/dist/{dist-Bz_sYWbr.js → dist-Bk75fBZA.js} +2 -2
- package/dist/dist-BlSvQzNr.js +5 -0
- package/dist/{dist-C5VC_yzu.js → dist-BzEzfugY.js} +1 -1
- package/dist/dist-CCBlxAgS.js +8 -0
- package/dist/dist-CIDTVIUf.js +5 -0
- package/dist/{dist-CLUtPrdy.js → dist-CIYBwstr.js} +1 -1
- package/dist/{dist-BotSqB48.js → dist-C_Y3oV3C.js} +12 -12
- package/dist/{dist-BTfv03uy.js → dist-CcWX6tmx.js} +2 -2
- package/dist/{dist-BhM8gdSO.js → dist-CoXAujgg.js} +4 -4
- package/dist/{dist-4j4c7bjm.js → dist-CpxNdDkw.js} +3 -3
- package/dist/dist-CqQyhAM8.js +8 -0
- package/dist/dist-CwRu2Xzh.js +5 -0
- package/dist/{dist-BcuoonNH.js → dist-CxJDU6Bh.js} +9 -9
- package/dist/{dist-DxvORzUR.js → dist-D-W5ny5a.js} +8 -8
- package/dist/dist-D8CDTVgf.js +6 -0
- package/dist/dist-D8DNB0nO.js +8 -0
- package/dist/dist-DL6N_q-A.js +5 -0
- package/dist/{dist-BbbIBDiQ.js → dist-DMjWuVs8.js} +1 -1
- package/dist/dist-DOFbNV_b.js +8 -0
- package/dist/dist-DPrYzMY0.js +6 -0
- package/dist/{dist-h2c8sZvT.js → dist-DZORgqKY.js} +1 -1
- package/dist/{dist-B3P2fFpz.js → dist-DZo4nSS0.js} +14 -14
- package/dist/{dist-D4CewLk6.js → dist-Dax--nl9.js} +1 -1
- package/dist/{dist-DRfcqpxJ.js → dist-DgGbNavJ.js} +2 -2
- package/dist/{dist-C1BYNeCR.js → dist-Dk6PV_d3.js} +10 -10
- package/dist/{dist-fQ0ViXGs.js → dist-Dv_Y15yk.js} +107 -107
- package/dist/{dist-Bfwsv11D.js → dist-DyyjKEYf.js} +2 -2
- package/dist/{dist-p2qyWijU.js → dist-GZXUmt0b.js} +2 -2
- package/dist/{dist-CLJWPTX2.js → dist-LTU8Hdvn.js} +3 -3
- package/dist/{dist-DqAWR3CS.js → dist-M9Vag9Y0.js} +20 -20
- package/dist/{dist-DNdhYsgW.js → dist-U4F-tbMs.js} +79 -62
- package/dist/{dist-RqXTaiir.js → dist-abid3KgM.js} +11 -11
- package/dist/dist-cdmMjgsn.js +5 -0
- package/dist/dist-hT4QzYX-.js +1247 -0
- package/dist/{dist-luvabDEB.js → dist-t9Kf7xqC.js} +2 -2
- package/dist/{error-banner-5bz0L9hS.js → error-banner-CJXYJ6Sb.js} +11 -6
- package/dist/esm-BaH2eg5-.js +1171 -0
- package/dist/{esm-Duie8iU-.js → esm-ga2Bf3O2.js} +43 -43
- package/dist/{extends-CkydH1Q5.js → extends-D_hDsj6R.js} +4 -4
- package/dist/files/wasm-intro.py +11 -8
- package/dist/{formats-DHxc-FdY.js → formats-C4wO47tk.js} +1 -1
- package/dist/{glide-data-editor-CgIxTzAP.js → glide-data-editor-BPkCPs7L.js} +255 -255
- package/dist/{html-to-image-B93KtAVY.js → html-to-image-BwfcJJxA.js} +2412 -2282
- package/dist/{input-_2sjvfne.js → input-OdWHkobi.js} +263 -245
- package/dist/{label-LWtdw5i8.js → label-CC4ytI1X.js} +1 -1
- package/dist/main.js +7630 -7558
- package/dist/{mermaid-4DMBBIKO-DIdL224_.js → mermaid-4DMBBIKO-Eg3D4FVz.js} +1 -1
- package/dist/{mermaid-lXOw5Py9.js → mermaid-BotvIKg9.js} +4 -4
- package/dist/{process-output-BOXi9fnS.js → process-output-DsloEDna.js} +3 -3
- package/dist/{reveal-component-gRcjQbNL.js → reveal-component-BOEk3vwx.js} +698 -620
- package/dist/{spec-B96zNUEA.js → spec-X7FwLJni.js} +4 -4
- package/dist/{strings-Bu3vlb6W.js → strings-J57tzLr3.js} +47 -46
- package/dist/style.css +1 -1
- package/dist/{toDate-x-WRDCH7.js → toDate-d8RCRrRd.js} +2 -2
- package/dist/{tooltip-C5FYOpQc.js → tooltip-DpcyNkQ2.js} +2 -2
- package/dist/{types-CVvp1fKr.js → types-ChtMFmZ2.js} +1 -1
- package/dist/{useAsyncData-iRgKDT5s.js → useAsyncData-PonK__yh.js} +1 -1
- package/dist/{useDateFormatter-BA4FCquG.js → useDateFormatter-QB-3MpYr.js} +2 -2
- package/dist/{useDeepCompareMemoize-CkQ57VS2.js → useDeepCompareMemoize-D3NGWke6.js} +1 -1
- package/dist/{useLifecycle-BBO9PIph.js → useLifecycle-00mO3OSS.js} +2 -2
- package/dist/{useTheme-DHIrRQOe.js → useTheme-DEhDzATN.js} +1 -1
- package/dist/{vega-component-Dq-SH463.js → vega-component-DGPUhbDs.js} +8 -8
- package/dist/{zod-CoBiJ5v4.js → zod-aLSua2NL.js} +24 -23
- package/package.json +4 -3
- package/src/__tests__/setup.ts +16 -0
- package/src/components/chat/chat-display.tsx +2 -2
- package/src/components/data-table/TableBottomBar.tsx +1 -15
- package/src/components/data-table/TableTopBar.tsx +8 -13
- package/src/components/data-table/__tests__/TableBottomBar.test.tsx +6 -12
- package/src/components/data-table/__tests__/column-visibility-dropdown.test.tsx +227 -0
- package/src/components/data-table/column-visibility-dropdown.tsx +204 -0
- package/src/components/data-table/data-table.tsx +1 -1
- package/src/components/data-table/filter-by-values-picker.tsx +39 -17
- package/src/components/data-table/filter-pills.tsx +1 -1
- package/src/components/datasources/__tests__/filter-empty.test.ts +183 -0
- package/src/components/datasources/datasources.tsx +92 -3
- package/src/components/editor/ai/ai-completion-editor.tsx +6 -5
- package/src/components/editor/cell/code/cell-editor.tsx +70 -32
- package/src/components/editor/cell/code/code-placeholder.css +18 -0
- package/src/components/editor/cell/code/code-placeholder.tsx +47 -0
- package/src/components/editor/cell/code/language-toggle.tsx +7 -1
- package/src/components/editor/chrome/wrapper/app-chrome.tsx +97 -52
- package/src/components/editor/chrome/wrapper/lazy-panels.ts +91 -0
- package/src/components/editor/chrome/wrapper/sidebar.tsx +2 -0
- package/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap +9 -2
- package/src/components/editor/connections/storage/__tests__/as-code.test.ts +62 -27
- package/src/components/editor/connections/storage/add-storage-form.tsx +5 -1
- package/src/components/editor/connections/storage/as-code.ts +20 -6
- package/src/components/editor/documentation.css +35 -0
- package/src/components/editor/file-tree/file-explorer.tsx +8 -18
- package/src/components/editor/file-tree/tree-actions.tsx +46 -1
- package/src/components/editor/notebook-cell.tsx +3 -3
- package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +20 -0
- package/src/components/editor/renderers/slides-layout/types.ts +1 -0
- package/src/components/markdown/__tests__/markdown-renderer.test.tsx +43 -0
- package/src/components/markdown/markdown-renderer.tsx +24 -1
- package/src/components/slides/__tests__/minimap-actions.test.tsx +166 -0
- package/src/components/slides/__tests__/reveal-component.test.ts +425 -0
- package/src/components/slides/minimap.tsx +127 -10
- package/src/components/slides/reveal-component.tsx +287 -61
- package/src/components/slides/slide-cell-view.tsx +26 -2
- package/src/components/slides/slide-form.tsx +26 -4
- package/src/components/storage/__tests__/storage-inspector.test.ts +180 -0
- package/src/components/storage/storage-inspector.tsx +535 -81
- package/src/components/ui/combobox.tsx +51 -32
- package/src/components/ui/number-field.tsx +5 -1
- package/src/components/ui/reorderable-list.tsx +13 -0
- package/src/components/ui/select-core/__tests__/use-select-list.test.ts +294 -0
- package/src/components/ui/select-core/__tests__/utils.test.ts +222 -0
- package/src/components/ui/select-core/index.ts +16 -0
- package/src/components/ui/select-core/option-row.tsx +33 -0
- package/src/components/ui/select-core/render-slot.ts +20 -0
- package/src/components/ui/select-core/select-list.tsx +248 -0
- package/src/components/ui/select-core/types.ts +44 -0
- package/src/components/ui/select-core/use-select-list.ts +347 -0
- package/src/components/ui/select-core/utils.ts +121 -0
- package/src/components/ui/toast.tsx +1 -0
- package/src/core/ai/__tests__/strip-wrapping-backticks.test.ts +133 -0
- package/src/core/ai/stream-completion-text.ts +48 -0
- package/src/core/ai/strip-wrapping-backticks.ts +88 -0
- package/src/core/cells/__tests__/document-changes.test.ts +2 -2
- package/src/core/cells/__tests__/focus.test.ts +45 -2
- package/src/core/cells/focus.ts +1 -1
- package/src/core/cells/scrollCellIntoView.ts +4 -0
- package/src/core/cells/utils.ts +1 -1
- package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +143 -0
- package/src/core/codemirror/ai/request.ts +2 -14
- package/src/core/codemirror/copilot/getCodes.ts +3 -1
- package/src/core/codemirror/editor-mount-scheduler.ts +101 -0
- package/src/core/codemirror/language/languages/python.ts +2 -0
- package/src/core/codemirror/language/languages/sql/utils.ts +3 -1
- package/src/core/codemirror/lsp/__tests__/markdown-renderer.test.ts +41 -0
- package/src/core/codemirror/lsp/markdown-renderer.ts +59 -0
- package/src/core/datasets/data-source-connections.ts +2 -0
- package/src/core/errors/errors.ts +1 -1
- package/src/core/storage/__tests__/state.test.ts +49 -0
- package/src/core/storage/__tests__/useStorageEntries.test.tsx +199 -3
- package/src/core/storage/state.ts +124 -13
- package/src/core/storage/types.ts +6 -0
- package/src/core/wasm/worker/bootstrap.ts +12 -4
- package/src/plugins/core/__test__/registerReactComponent.test.ts +96 -0
- package/src/plugins/core/registerReactComponent.tsx +42 -10
- package/src/plugins/impl/MultiselectPlugin.tsx +19 -142
- package/src/plugins/impl/SearchableSelect.tsx +16 -97
- package/src/plugins/impl/SliderPlugin.tsx +132 -18
- package/src/plugins/impl/__tests__/DropdownPlugin.test.tsx +5 -2
- package/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts +1 -1
- package/src/plugins/impl/__tests__/SliderPlugin.test.tsx +278 -8
- package/src/utils/__tests__/numbers.test.ts +20 -0
- package/src/utils/errors.ts +9 -0
- package/src/utils/lazy.ts +6 -1
- package/src/utils/numbers.ts +27 -0
- package/src/utils/schedule-task.ts +71 -0
- package/dist/assets/__vite-browser-external-Ci2ZQfXU.js +0 -1
- package/dist/assets/worker-ip3AI_sN.js +0 -73
- package/dist/dist-0Fif7jnk.js +0 -5
- package/dist/dist-B5h_9sHB.js +0 -6
- package/dist/dist-B9M6R5ye.js +0 -5
- package/dist/dist-BCt3tnck.js +0 -8
- package/dist/dist-BUIJwMwn.js +0 -8
- package/dist/dist-BpquMd3k.js +0 -5
- package/dist/dist-BzJsqYfz.js +0 -5
- package/dist/dist-CA5ELXAf.js +0 -6
- package/dist/dist-CLBRs6Uv.js +0 -5
- package/dist/dist-CStVCMbq.js +0 -5
- package/dist/dist-CZRIEY3Y.js +0 -8
- package/dist/dist-CuUHbFD0.js +0 -5
- package/dist/dist-DV7Iabxb.js +0 -8
- package/dist/dist-DhHh0jLg.js +0 -1247
- package/dist/dist-DuEeHMvL.js +0 -5
- package/dist/esm-CCuYCd3R.js +0 -1171
- package/src/plugins/impl/multiselectFilterFn.tsx +0 -22
- /package/src/components/{data-table → ui}/value-chips.tsx +0 -0
|
@@ -48,6 +48,7 @@ describe("storage state", () => {
|
|
|
48
48
|
expect(state).toEqual({
|
|
49
49
|
namespaces: [],
|
|
50
50
|
entriesByPath: new Map(),
|
|
51
|
+
pageMetadataByPath: new Map(),
|
|
51
52
|
});
|
|
52
53
|
});
|
|
53
54
|
});
|
|
@@ -134,6 +135,49 @@ describe("storage state", () => {
|
|
|
134
135
|
expect(state.entriesByPath.get("my_s3::data/")).toEqual(entries);
|
|
135
136
|
});
|
|
136
137
|
|
|
138
|
+
it("should store next page tokens keyed by namespace and prefix", () => {
|
|
139
|
+
const entries = [makeEntry({ path: "a.txt" })];
|
|
140
|
+
|
|
141
|
+
actions.setEntries({
|
|
142
|
+
namespace: "my_s3",
|
|
143
|
+
prefix: "data/",
|
|
144
|
+
entries,
|
|
145
|
+
nextPageToken: "150",
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(state.entriesByPath.get("my_s3::data/")).toEqual(entries);
|
|
149
|
+
expect(state.pageMetadataByPath.get("my_s3::data/")?.nextPageToken).toBe(
|
|
150
|
+
"150",
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should append entries when requested", () => {
|
|
155
|
+
const firstPage = [makeEntry({ path: "a.txt" })];
|
|
156
|
+
const secondPage = [makeEntry({ path: "b.txt" })];
|
|
157
|
+
|
|
158
|
+
actions.setEntries({
|
|
159
|
+
namespace: "my_s3",
|
|
160
|
+
prefix: "data/",
|
|
161
|
+
entries: firstPage,
|
|
162
|
+
nextPageToken: "150",
|
|
163
|
+
});
|
|
164
|
+
actions.setEntries({
|
|
165
|
+
namespace: "my_s3",
|
|
166
|
+
prefix: "data/",
|
|
167
|
+
entries: secondPage,
|
|
168
|
+
nextPageToken: null,
|
|
169
|
+
append: true,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
expect(state.entriesByPath.get("my_s3::data/")).toEqual([
|
|
173
|
+
...firstPage,
|
|
174
|
+
...secondPage,
|
|
175
|
+
]);
|
|
176
|
+
expect(
|
|
177
|
+
state.pageMetadataByPath.get("my_s3::data/")?.nextPageToken,
|
|
178
|
+
).toBeNull();
|
|
179
|
+
});
|
|
180
|
+
|
|
137
181
|
it("should use empty string for null prefix", () => {
|
|
138
182
|
const entries = [makeEntry({ path: "root.txt" })];
|
|
139
183
|
|
|
@@ -251,6 +295,11 @@ describe("storage state", () => {
|
|
|
251
295
|
expect(state.entriesByPath.get("my_s3::")).toBeUndefined();
|
|
252
296
|
expect(state.entriesByPath.get("my_s3::data/")).toBeUndefined();
|
|
253
297
|
expect(state.entriesByPath.get("my_s3::data/nested/")).toBeUndefined();
|
|
298
|
+
expect(state.pageMetadataByPath.get("my_s3::")).toBeUndefined();
|
|
299
|
+
expect(state.pageMetadataByPath.get("my_s3::data/")).toBeUndefined();
|
|
300
|
+
expect(
|
|
301
|
+
state.pageMetadataByPath.get("my_s3::data/nested/"),
|
|
302
|
+
).toBeUndefined();
|
|
254
303
|
});
|
|
255
304
|
|
|
256
305
|
it("should not affect entries from other namespaces", () => {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { renderHook, waitFor } from "@testing-library/react";
|
|
3
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
4
4
|
import { createStore, Provider } from "jotai";
|
|
5
5
|
import type { ReactNode } from "react";
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
storageAtom,
|
|
10
|
+
useStorageEntries,
|
|
11
|
+
useStoragePageFetcher,
|
|
12
|
+
} from "../state";
|
|
9
13
|
import type { StorageEntry, StorageState } from "../types";
|
|
10
14
|
|
|
11
15
|
const mockRequest = vi.fn();
|
|
@@ -175,13 +179,205 @@ describe("useStorageEntries", () => {
|
|
|
175
179
|
|
|
176
180
|
it("should store fetched entries in the atom", async () => {
|
|
177
181
|
const entries = [makeEntry({ path: "new.txt" })];
|
|
178
|
-
mockRequest.mockResolvedValue({
|
|
182
|
+
mockRequest.mockResolvedValue({
|
|
183
|
+
entries,
|
|
184
|
+
next_page_token: "150",
|
|
185
|
+
});
|
|
179
186
|
|
|
180
187
|
renderHook(() => useStorageEntries("ns", "sub/"), { wrapper });
|
|
181
188
|
|
|
182
189
|
await waitFor(() => {
|
|
183
190
|
const state = store.get(storageAtom);
|
|
184
191
|
expect(state.entriesByPath.get("ns::sub/")).toEqual(entries);
|
|
192
|
+
expect(state.pageMetadataByPath.get("ns::sub/")?.nextPageToken).toBe(
|
|
193
|
+
"150",
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should load more entries when a next page token exists", async () => {
|
|
199
|
+
const firstPage = [makeEntry({ path: "a.txt" })];
|
|
200
|
+
const secondPage = [makeEntry({ path: "b.txt" })];
|
|
201
|
+
mockRequest
|
|
202
|
+
.mockResolvedValueOnce({
|
|
203
|
+
entries: firstPage,
|
|
204
|
+
next_page_token: "150",
|
|
205
|
+
})
|
|
206
|
+
.mockResolvedValueOnce({
|
|
207
|
+
entries: secondPage,
|
|
208
|
+
next_page_token: null,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const { result } = renderHook(() => useStorageEntries("ns", "sub/"), {
|
|
212
|
+
wrapper,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
await waitFor(() => {
|
|
216
|
+
expect(result.current.entries).toEqual(firstPage);
|
|
217
|
+
});
|
|
218
|
+
expect(result.current.hasMore).toBe(true);
|
|
219
|
+
|
|
220
|
+
await act(async () => {
|
|
221
|
+
await result.current.loadMore();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
expect(result.current.entries).toEqual([...firstPage, ...secondPage]);
|
|
225
|
+
expect(result.current.hasMore).toBe(false);
|
|
226
|
+
expect(mockRequest).toHaveBeenLastCalledWith({
|
|
227
|
+
namespace: "ns",
|
|
228
|
+
prefix: "sub/",
|
|
229
|
+
limit: 150,
|
|
230
|
+
pageToken: "150",
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("should load more entries when the next page token is an empty string", async () => {
|
|
235
|
+
const firstPage = [makeEntry({ path: "a.txt" })];
|
|
236
|
+
const secondPage = [makeEntry({ path: "b.txt" })];
|
|
237
|
+
mockRequest
|
|
238
|
+
.mockResolvedValueOnce({
|
|
239
|
+
entries: firstPage,
|
|
240
|
+
next_page_token: "",
|
|
241
|
+
})
|
|
242
|
+
.mockResolvedValueOnce({
|
|
243
|
+
entries: secondPage,
|
|
244
|
+
next_page_token: null,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const { result } = renderHook(() => useStorageEntries("ns", "sub/"), {
|
|
248
|
+
wrapper,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
await waitFor(() => {
|
|
252
|
+
expect(result.current.entries).toEqual(firstPage);
|
|
253
|
+
});
|
|
254
|
+
expect(result.current.hasMore).toBe(true);
|
|
255
|
+
|
|
256
|
+
await act(async () => {
|
|
257
|
+
await result.current.loadMore();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
expect(result.current.entries).toEqual([...firstPage, ...secondPage]);
|
|
261
|
+
expect(result.current.hasMore).toBe(false);
|
|
262
|
+
expect(mockRequest).toHaveBeenLastCalledWith({
|
|
263
|
+
namespace: "ns",
|
|
264
|
+
prefix: "sub/",
|
|
265
|
+
limit: 150,
|
|
266
|
+
pageToken: "",
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should ignore duplicate load more calls while a page is loading", async () => {
|
|
271
|
+
const firstPage = [makeEntry({ path: "a.txt" })];
|
|
272
|
+
const secondPage = [makeEntry({ path: "b.txt" })];
|
|
273
|
+
let resolveLoadMore!: (value: {
|
|
274
|
+
entries: StorageEntry[];
|
|
275
|
+
next_page_token: string | null;
|
|
276
|
+
}) => void;
|
|
277
|
+
const loadMorePromise = new Promise<{
|
|
278
|
+
entries: StorageEntry[];
|
|
279
|
+
next_page_token: string | null;
|
|
280
|
+
}>((resolve) => {
|
|
281
|
+
resolveLoadMore = resolve;
|
|
282
|
+
});
|
|
283
|
+
mockRequest
|
|
284
|
+
.mockResolvedValueOnce({
|
|
285
|
+
entries: firstPage,
|
|
286
|
+
next_page_token: "150",
|
|
287
|
+
})
|
|
288
|
+
.mockReturnValueOnce(loadMorePromise);
|
|
289
|
+
|
|
290
|
+
const { result } = renderHook(() => useStorageEntries("ns", "sub/"), {
|
|
291
|
+
wrapper,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
await waitFor(() => {
|
|
295
|
+
expect(result.current.entries).toEqual(firstPage);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
await act(async () => {
|
|
299
|
+
const firstLoad = result.current.loadMore();
|
|
300
|
+
const secondLoad = result.current.loadMore();
|
|
301
|
+
|
|
302
|
+
expect(mockRequest).toHaveBeenCalledTimes(2);
|
|
303
|
+
resolveLoadMore({
|
|
304
|
+
entries: secondPage,
|
|
305
|
+
next_page_token: null,
|
|
306
|
+
});
|
|
307
|
+
await Promise.all([firstLoad, secondLoad]);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
expect(result.current.entries).toEqual([...firstPage, ...secondPage]);
|
|
311
|
+
expect(mockRequest).toHaveBeenCalledTimes(2);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("should fetch arbitrary storage pages", async () => {
|
|
315
|
+
const firstPage = [makeEntry({ path: "folder/a.txt" })];
|
|
316
|
+
const secondPage = [makeEntry({ path: "folder/b.txt" })];
|
|
317
|
+
mockRequest
|
|
318
|
+
.mockResolvedValueOnce({
|
|
319
|
+
entries: firstPage,
|
|
320
|
+
next_page_token: "150",
|
|
321
|
+
})
|
|
322
|
+
.mockResolvedValueOnce({
|
|
323
|
+
entries: secondPage,
|
|
324
|
+
next_page_token: null,
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const { result } = renderHook(() => useStoragePageFetcher(), {
|
|
328
|
+
wrapper,
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
await act(async () => {
|
|
332
|
+
await result.current({
|
|
333
|
+
namespace: "ns",
|
|
334
|
+
prefix: "folder/",
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
await act(async () => {
|
|
338
|
+
await result.current({
|
|
339
|
+
namespace: "ns",
|
|
340
|
+
prefix: "folder/",
|
|
341
|
+
pageToken: "150",
|
|
342
|
+
append: true,
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
expect(store.get(storageAtom).entriesByPath.get("ns::folder/")).toEqual([
|
|
347
|
+
...firstPage,
|
|
348
|
+
...secondPage,
|
|
349
|
+
]);
|
|
350
|
+
expect(mockRequest).toHaveBeenLastCalledWith({
|
|
351
|
+
namespace: "ns",
|
|
352
|
+
prefix: "folder/",
|
|
353
|
+
limit: 150,
|
|
354
|
+
pageToken: "150",
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("should forward an empty string page token", async () => {
|
|
359
|
+
mockRequest.mockResolvedValue({
|
|
360
|
+
entries: [],
|
|
361
|
+
next_page_token: null,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
const { result } = renderHook(() => useStoragePageFetcher(), {
|
|
365
|
+
wrapper,
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
await act(async () => {
|
|
369
|
+
await result.current({
|
|
370
|
+
namespace: "ns",
|
|
371
|
+
prefix: "folder/",
|
|
372
|
+
pageToken: "",
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
expect(mockRequest).toHaveBeenLastCalledWith({
|
|
377
|
+
namespace: "ns",
|
|
378
|
+
prefix: "folder/",
|
|
379
|
+
limit: 150,
|
|
380
|
+
pageToken: "",
|
|
185
381
|
});
|
|
186
382
|
});
|
|
187
383
|
});
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { atom, useAtomValue } from "jotai";
|
|
4
|
+
import { useCallback, useRef, useState } from "react";
|
|
4
5
|
import { useAsyncData } from "@/hooks/useAsyncData";
|
|
5
6
|
import { createReducerAndAtoms } from "@/utils/createReducer";
|
|
6
7
|
import type { NotificationMessageData } from "../kernel/messages";
|
|
7
8
|
import type { VariableName } from "../variables/types";
|
|
8
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
ListStorageEntries,
|
|
11
|
+
type StorageEntriesResult,
|
|
12
|
+
} from "./request-registry";
|
|
9
13
|
import type { StorageEntry, StorageState } from "./types";
|
|
10
14
|
import {
|
|
11
15
|
DEFAULT_FETCH_LIMIT,
|
|
@@ -18,6 +22,7 @@ function initialState(): StorageState {
|
|
|
18
22
|
return {
|
|
19
23
|
namespaces: [],
|
|
20
24
|
entriesByPath: new Map(),
|
|
25
|
+
pageMetadataByPath: new Map(),
|
|
21
26
|
};
|
|
22
27
|
}
|
|
23
28
|
|
|
@@ -48,23 +53,48 @@ const {
|
|
|
48
53
|
namespace: string;
|
|
49
54
|
prefix: string | null | undefined;
|
|
50
55
|
entries: StorageEntry[];
|
|
56
|
+
nextPageToken?: string | null;
|
|
57
|
+
append?: boolean;
|
|
51
58
|
},
|
|
52
59
|
) => {
|
|
53
60
|
const key = storagePathKey(opts.namespace, opts.prefix);
|
|
54
61
|
const entriesByPath = new Map(state.entriesByPath);
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
const entries =
|
|
63
|
+
opts.append && entriesByPath.has(key)
|
|
64
|
+
? [...(entriesByPath.get(key) ?? []), ...opts.entries]
|
|
65
|
+
: opts.entries;
|
|
66
|
+
entriesByPath.set(key, entries);
|
|
67
|
+
|
|
68
|
+
const pageMetadataByPath = new Map(state.pageMetadataByPath);
|
|
69
|
+
pageMetadataByPath.set(key, {
|
|
70
|
+
nextPageToken: opts.nextPageToken ?? null,
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
entriesByPath,
|
|
75
|
+
pageMetadataByPath,
|
|
76
|
+
};
|
|
57
77
|
},
|
|
58
78
|
|
|
59
79
|
clearNamespaceCache: (state, namespace: string) => {
|
|
60
80
|
const entriesByPath = new Map(state.entriesByPath);
|
|
81
|
+
const pageMetadataByPath = new Map(state.pageMetadataByPath);
|
|
61
82
|
const prefix = storageNamespacePrefix(namespace);
|
|
62
83
|
for (const key of entriesByPath.keys()) {
|
|
63
84
|
if (key.startsWith(prefix)) {
|
|
64
85
|
entriesByPath.delete(key);
|
|
65
86
|
}
|
|
66
87
|
}
|
|
67
|
-
|
|
88
|
+
for (const key of pageMetadataByPath.keys()) {
|
|
89
|
+
if (key.startsWith(prefix)) {
|
|
90
|
+
pageMetadataByPath.delete(key);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
...state,
|
|
95
|
+
entriesByPath,
|
|
96
|
+
pageMetadataByPath,
|
|
97
|
+
};
|
|
68
98
|
},
|
|
69
99
|
|
|
70
100
|
filterFromVariables: (state, variableNames: VariableName[]) => {
|
|
@@ -93,38 +123,119 @@ export function useStorageActions() {
|
|
|
93
123
|
|
|
94
124
|
export { storageAtom };
|
|
95
125
|
|
|
126
|
+
async function fetchStorageEntriesPage({
|
|
127
|
+
namespace,
|
|
128
|
+
prefix,
|
|
129
|
+
pageToken,
|
|
130
|
+
append,
|
|
131
|
+
setEntries,
|
|
132
|
+
}: {
|
|
133
|
+
namespace: string;
|
|
134
|
+
prefix: string | null | undefined;
|
|
135
|
+
pageToken?: string | null;
|
|
136
|
+
append?: boolean;
|
|
137
|
+
setEntries: ReturnType<typeof useStorageActions>["setEntries"];
|
|
138
|
+
}): Promise<StorageEntriesResult> {
|
|
139
|
+
const result = await ListStorageEntries.request({
|
|
140
|
+
namespace,
|
|
141
|
+
prefix: prefix ?? ROOT_PATH,
|
|
142
|
+
limit: DEFAULT_FETCH_LIMIT,
|
|
143
|
+
...(pageToken != null ? { pageToken } : {}),
|
|
144
|
+
});
|
|
145
|
+
if (result.error) {
|
|
146
|
+
throw new Error(result.error);
|
|
147
|
+
}
|
|
148
|
+
setEntries({
|
|
149
|
+
namespace,
|
|
150
|
+
prefix,
|
|
151
|
+
entries: result.entries,
|
|
152
|
+
nextPageToken: result.next_page_token,
|
|
153
|
+
append,
|
|
154
|
+
});
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
|
|
96
158
|
/**
|
|
97
159
|
* Hook that fetches and caches storage entries for a given namespace/prefix.
|
|
98
160
|
* Entries are fetched on first access and cached in the store for subsequent renders.
|
|
99
161
|
*/
|
|
100
162
|
export function useStorageEntries(namespace: string, prefix?: string) {
|
|
101
|
-
const { entriesByPath } = useStorage();
|
|
163
|
+
const { entriesByPath, pageMetadataByPath } = useStorage();
|
|
102
164
|
const { setEntries } = useStorageActions();
|
|
103
|
-
const
|
|
165
|
+
const key = storagePathKey(namespace, prefix);
|
|
166
|
+
const cached = entriesByPath.get(key);
|
|
167
|
+
const metadata = pageMetadataByPath.get(key);
|
|
168
|
+
const nextPageToken = metadata?.nextPageToken ?? null;
|
|
169
|
+
const isLoadingMoreRef = useRef(false);
|
|
170
|
+
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
171
|
+
const [loadMoreError, setLoadMoreError] = useState<Error | undefined>();
|
|
104
172
|
|
|
105
173
|
const { isPending, error, refetch } = useAsyncData(async () => {
|
|
106
174
|
if (cached) {
|
|
107
175
|
return;
|
|
108
176
|
}
|
|
109
|
-
|
|
177
|
+
await fetchStorageEntriesPage({
|
|
110
178
|
namespace,
|
|
111
|
-
prefix
|
|
112
|
-
|
|
179
|
+
prefix,
|
|
180
|
+
setEntries,
|
|
113
181
|
});
|
|
114
|
-
if (result.error) {
|
|
115
|
-
throw new Error(result.error);
|
|
116
|
-
}
|
|
117
|
-
setEntries({ namespace, prefix, entries: result.entries });
|
|
118
182
|
}, [namespace, prefix, cached === undefined]);
|
|
119
183
|
|
|
184
|
+
const loadMore = useCallback(async () => {
|
|
185
|
+
if (nextPageToken == null || isLoadingMoreRef.current) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
isLoadingMoreRef.current = true;
|
|
190
|
+
setIsLoadingMore(true);
|
|
191
|
+
setLoadMoreError(undefined);
|
|
192
|
+
try {
|
|
193
|
+
await fetchStorageEntriesPage({
|
|
194
|
+
namespace,
|
|
195
|
+
prefix,
|
|
196
|
+
pageToken: nextPageToken,
|
|
197
|
+
append: true,
|
|
198
|
+
setEntries,
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
setLoadMoreError(
|
|
202
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
203
|
+
);
|
|
204
|
+
} finally {
|
|
205
|
+
isLoadingMoreRef.current = false;
|
|
206
|
+
setIsLoadingMore(false);
|
|
207
|
+
}
|
|
208
|
+
}, [namespace, prefix, nextPageToken, setEntries]);
|
|
209
|
+
|
|
120
210
|
return {
|
|
121
211
|
entries: cached ?? [],
|
|
122
212
|
isPending: isPending && !cached,
|
|
123
213
|
error: cached ? undefined : error,
|
|
214
|
+
hasMore: nextPageToken !== null,
|
|
215
|
+
loadMore,
|
|
216
|
+
isLoadingMore,
|
|
217
|
+
loadMoreError,
|
|
124
218
|
refetch,
|
|
125
219
|
};
|
|
126
220
|
}
|
|
127
221
|
|
|
222
|
+
export function useStoragePageFetcher() {
|
|
223
|
+
const { setEntries } = useStorageActions();
|
|
224
|
+
return useCallback(
|
|
225
|
+
(opts: {
|
|
226
|
+
namespace: string;
|
|
227
|
+
prefix: string | null | undefined;
|
|
228
|
+
pageToken?: string | null;
|
|
229
|
+
append?: boolean;
|
|
230
|
+
}) =>
|
|
231
|
+
fetchStorageEntriesPage({
|
|
232
|
+
...opts,
|
|
233
|
+
setEntries,
|
|
234
|
+
}),
|
|
235
|
+
[setEntries],
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
128
239
|
export const exportedForTesting = {
|
|
129
240
|
reducer,
|
|
130
241
|
createActions,
|
|
@@ -30,6 +30,12 @@ export interface StorageState {
|
|
|
30
30
|
namespaces: StorageNamespace[];
|
|
31
31
|
/** Lazy-loaded entries keyed by "namespace::prefix" */
|
|
32
32
|
entriesByPath: ReadonlyMap<StoragePathKey, StorageEntry[]>;
|
|
33
|
+
/** Pagination metadata keyed by "namespace::prefix" */
|
|
34
|
+
pageMetadataByPath: ReadonlyMap<StoragePathKey, StoragePageMetadata>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface StoragePageMetadata {
|
|
38
|
+
nextPageToken: string | null;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
export function storageUrl(
|
|
@@ -55,6 +55,10 @@ export class DefaultWasmController implements WasmController {
|
|
|
55
55
|
// Load pyodide and packages
|
|
56
56
|
const span = t.startSpan("loadPyodide");
|
|
57
57
|
try {
|
|
58
|
+
// Without this, this fails in Firefox with
|
|
59
|
+
// `Could not extract indexURL path from pyodide module`
|
|
60
|
+
// This fixes for Firefox and does not break Chrome/others
|
|
61
|
+
const indexURL = `https://cdn.jsdelivr.net/pyodide/${opts.pyodideVersion}/full/`;
|
|
58
62
|
const pyodide = await loadPyodide({
|
|
59
63
|
// Perf: These get loaded while pyodide is being bootstrapped
|
|
60
64
|
packages: [
|
|
@@ -68,10 +72,14 @@ export class DefaultWasmController implements WasmController {
|
|
|
68
72
|
],
|
|
69
73
|
_makeSnapshot: MAKE_SNAPSHOT,
|
|
70
74
|
lockFileURL: `https://wasm.marimo.app/pyodide-lock.json?v=${opts.version}&pyodide=${opts.pyodideVersion}`,
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
+
indexURL,
|
|
76
|
+
// Since Pyodide 0.28.0, when lockFileURL is set, the package base URL
|
|
77
|
+
// defaults to the lockfile's URL (wasm.marimo.app) instead of indexURL.
|
|
78
|
+
// Unlike Node, browsers get no CDN fallback on a failed fetch, so we
|
|
79
|
+
// should pin packageBaseUrl back to the jsDelivr CDN to restore
|
|
80
|
+
// the resolution akin to pre-0.28.
|
|
81
|
+
packageBaseUrl: indexURL,
|
|
82
|
+
convertNullToNone: true,
|
|
75
83
|
});
|
|
76
84
|
this.pyodide = pyodide;
|
|
77
85
|
span.end("ok");
|
|
@@ -3,11 +3,20 @@
|
|
|
3
3
|
import ReactDOM from "react-dom/client";
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { FUNCTIONS_REGISTRY } from "@/core/functions/FunctionRegistry";
|
|
7
|
+
import type { FunctionCallResultMessage } from "@/core/kernel/messages";
|
|
8
|
+
import { FunctionNotFoundError } from "@/utils/errors";
|
|
6
9
|
import {
|
|
7
10
|
isCustomMarimoElement,
|
|
8
11
|
registerReactComponent,
|
|
9
12
|
} from "../registerReactComponent";
|
|
10
13
|
|
|
14
|
+
vi.mock("@/core/functions/FunctionRegistry", () => ({
|
|
15
|
+
FUNCTIONS_REGISTRY: { request: vi.fn() },
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const requestMock = vi.mocked(FUNCTIONS_REGISTRY.request);
|
|
19
|
+
|
|
11
20
|
// Each custom element name can only be registered once per jsdom window,
|
|
12
21
|
// so we use a counter to generate unique tag names across tests.
|
|
13
22
|
let tagCounter = 0;
|
|
@@ -202,3 +211,90 @@ describe("connectedCallback - light DOM nesting detection", () => {
|
|
|
202
211
|
outer.remove();
|
|
203
212
|
});
|
|
204
213
|
});
|
|
214
|
+
|
|
215
|
+
describe("plugin function: not-found recovery", () => {
|
|
216
|
+
const NOT_FOUND: FunctionCallResultMessage = {
|
|
217
|
+
function_call_id:
|
|
218
|
+
"call-id" as FunctionCallResultMessage["function_call_id"],
|
|
219
|
+
status: { code: "error", message: "Function not found" },
|
|
220
|
+
found: false,
|
|
221
|
+
return_value: null,
|
|
222
|
+
};
|
|
223
|
+
const OK: FunctionCallResultMessage = {
|
|
224
|
+
function_call_id:
|
|
225
|
+
"call-id" as FunctionCallResultMessage["function_call_id"],
|
|
226
|
+
status: { code: "ok" },
|
|
227
|
+
found: true,
|
|
228
|
+
return_value: { ok: true },
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// Mount a plugin exposing a single callable function and resolve the
|
|
232
|
+
// function map that PluginSlot hands to render(), so tests can invoke the
|
|
233
|
+
// request path directly.
|
|
234
|
+
async function mountWithFunction(): Promise<
|
|
235
|
+
(args: Record<string, unknown>) => Promise<unknown>
|
|
236
|
+
> {
|
|
237
|
+
const tag = uniqueTag("fn");
|
|
238
|
+
let captured:
|
|
239
|
+
| ((args: Record<string, unknown>) => Promise<unknown>)
|
|
240
|
+
| undefined;
|
|
241
|
+
registerReactComponent({
|
|
242
|
+
tagName: tag,
|
|
243
|
+
validator: z.any(),
|
|
244
|
+
functions: { run: { input: z.any(), output: z.any() } },
|
|
245
|
+
render: ({ functions }) => {
|
|
246
|
+
captured = (functions as Record<string, typeof captured>).run;
|
|
247
|
+
return null as never;
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const wrapper = document.createElement("marimo-ui-element");
|
|
252
|
+
wrapper.setAttribute("object-id", "test-object-id");
|
|
253
|
+
const el = document.createElement(tag);
|
|
254
|
+
wrapper.append(el);
|
|
255
|
+
document.body.append(wrapper);
|
|
256
|
+
|
|
257
|
+
await vi.waitFor(() => expect(captured).toBeDefined());
|
|
258
|
+
return captured as (args: Record<string, unknown>) => Promise<unknown>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
requestMock.mockReset();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
afterEach(() => {
|
|
266
|
+
document.body.innerHTML = "";
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("retries on found:false and resolves once the function appears", async () => {
|
|
270
|
+
const run = await mountWithFunction();
|
|
271
|
+
requestMock.mockResolvedValueOnce(NOT_FOUND).mockResolvedValueOnce(OK);
|
|
272
|
+
|
|
273
|
+
await expect(run({})).resolves.toEqual({ ok: true });
|
|
274
|
+
expect(requestMock).toHaveBeenCalledTimes(2);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("throws FunctionNotFoundError after retries are exhausted", async () => {
|
|
278
|
+
const run = await mountWithFunction();
|
|
279
|
+
requestMock.mockResolvedValue(NOT_FOUND);
|
|
280
|
+
|
|
281
|
+
await expect(run({})).rejects.toBeInstanceOf(FunctionNotFoundError);
|
|
282
|
+
// Initial attempt plus three retries.
|
|
283
|
+
expect(requestMock).toHaveBeenCalledTimes(4);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("does not retry once the function is found (found:true)", async () => {
|
|
287
|
+
const run = await mountWithFunction();
|
|
288
|
+
requestMock.mockResolvedValue({
|
|
289
|
+
function_call_id:
|
|
290
|
+
"call-id" as FunctionCallResultMessage["function_call_id"],
|
|
291
|
+
status: { code: "error", message: "boom" },
|
|
292
|
+
found: true,
|
|
293
|
+
return_value: null,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const promise = run({});
|
|
297
|
+
await expect(promise).rejects.toThrow("boom");
|
|
298
|
+
expect(requestMock).toHaveBeenCalledTimes(1);
|
|
299
|
+
});
|
|
300
|
+
});
|