@agent-native/core 0.114.0 → 0.114.1

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.
Files changed (162) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +9 -0
  3. package/corpus/core/package.json +1 -1
  4. package/corpus/core/src/client/build-compatibility.ts +77 -0
  5. package/corpus/core/src/client/route-chunk-recovery/index.ts +1 -0
  6. package/corpus/core/src/client/use-action.ts +32 -1
  7. package/corpus/core/src/deploy/build.ts +4 -1
  8. package/corpus/core/src/org/context.ts +56 -30
  9. package/corpus/core/src/server/action-routes.ts +52 -2
  10. package/corpus/core/src/server/auth-plugin.ts +9 -4
  11. package/corpus/core/src/server/better-auth-instance.ts +5 -1
  12. package/corpus/core/src/shared/mcp-embed-headers.ts +1 -1
  13. package/corpus/core/src/vite/client.ts +17 -0
  14. package/corpus/templates/content/AGENTS.md +2 -0
  15. package/corpus/templates/content/actions/_content-database-personal-view.ts +49 -5
  16. package/corpus/templates/content/actions/_content-document-access.ts +21 -0
  17. package/corpus/templates/content/actions/_content-favorites.ts +91 -0
  18. package/corpus/templates/content/actions/_content-files.ts +79 -23
  19. package/corpus/templates/content/actions/_content-sidebar-state.ts +24 -0
  20. package/corpus/templates/content/actions/_content-space-access.ts +15 -17
  21. package/corpus/templates/content/actions/_content-space-catalog-guards.ts +20 -0
  22. package/corpus/templates/content/actions/_content-spaces.ts +364 -167
  23. package/corpus/templates/content/actions/_database-source-utils.ts +8 -0
  24. package/corpus/templates/content/actions/_database-utils.ts +249 -15
  25. package/corpus/templates/content/actions/_delete-content-space.ts +84 -0
  26. package/corpus/templates/content/actions/_files-system-properties.ts +499 -0
  27. package/corpus/templates/content/actions/_local-file-documents.ts +0 -1
  28. package/corpus/templates/content/actions/_property-utils.ts +18 -9
  29. package/corpus/templates/content/actions/bind-content-database-source-field.ts +3 -0
  30. package/corpus/templates/content/actions/configure-document-property.ts +3 -0
  31. package/corpus/templates/content/actions/create-content-database.ts +2 -2
  32. package/corpus/templates/content/actions/create-content-space.ts +34 -0
  33. package/corpus/templates/content/actions/create-document.ts +4 -1
  34. package/corpus/templates/content/actions/delete-content-space.ts +19 -0
  35. package/corpus/templates/content/actions/delete-database-items.ts +28 -1
  36. package/corpus/templates/content/actions/delete-document-property.ts +3 -0
  37. package/corpus/templates/content/actions/delete-document.ts +39 -2
  38. package/corpus/templates/content/actions/duplicate-database-item.ts +6 -0
  39. package/corpus/templates/content/actions/duplicate-database-items.ts +6 -0
  40. package/corpus/templates/content/actions/duplicate-document-property.ts +3 -0
  41. package/corpus/templates/content/actions/get-content-database.ts +11 -2
  42. package/corpus/templates/content/actions/get-content-sidebar-state.ts +23 -0
  43. package/corpus/templates/content/actions/get-document.ts +32 -7
  44. package/corpus/templates/content/actions/import-content-source.ts +33 -1
  45. package/corpus/templates/content/actions/list-content-spaces.ts +34 -2
  46. package/corpus/templates/content/actions/list-documents.ts +39 -7
  47. package/corpus/templates/content/actions/reorder-document-property.ts +9 -0
  48. package/corpus/templates/content/actions/set-document-property.ts +41 -23
  49. package/corpus/templates/content/actions/share-local-file-document.ts +15 -0
  50. package/corpus/templates/content/actions/submit-content-database-form.ts +7 -0
  51. package/corpus/templates/content/actions/sync-local-folder-source.ts +14 -0
  52. package/corpus/templates/content/actions/update-content-database-view.ts +1 -0
  53. package/corpus/templates/content/actions/update-content-sidebar-state.ts +27 -0
  54. package/corpus/templates/content/actions/update-document.ts +158 -66
  55. package/corpus/templates/content/app/components/EmptyState.tsx +4 -57
  56. package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +8 -1
  57. package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +519 -178
  58. package/corpus/templates/content/app/components/editor/DocumentInfoPanel.tsx +39 -0
  59. package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +1 -1
  60. package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +266 -7
  61. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +430 -152
  62. package/corpus/templates/content/app/components/editor/database/sidebar.tsx +467 -66
  63. package/corpus/templates/content/app/components/editor/database/view-config.ts +9 -3
  64. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +720 -196
  65. package/corpus/templates/content/app/components/sidebar/DocumentTreeItem.tsx +173 -1
  66. package/corpus/templates/content/app/components/sidebar/document-sidebar-sections.ts +1 -1
  67. package/corpus/templates/content/app/components/sidebar/select-content-space.ts +91 -16
  68. package/corpus/templates/content/app/entry.client.tsx +5 -1
  69. package/corpus/templates/content/app/hooks/use-content-database.ts +84 -3
  70. package/corpus/templates/content/app/hooks/use-content-spaces.ts +60 -2
  71. package/corpus/templates/content/app/hooks/use-create-page.ts +30 -0
  72. package/corpus/templates/content/app/hooks/use-documents.ts +270 -19
  73. package/corpus/templates/content/app/i18n-data.ts +243 -20
  74. package/corpus/templates/content/app/lib/local-folder-picker-safety.ts +54 -0
  75. package/corpus/templates/content/app/lib/local-folder-picker-support.ts +18 -0
  76. package/corpus/templates/content/app/routes/_app.favorites.tsx +30 -0
  77. package/corpus/templates/content/app/routes/_app.local-files.tsx +18 -6
  78. package/corpus/templates/content/changelog/2026-07-17-workspace-files-now-stay-in-a-loading-state-until-automatic-.md +6 -0
  79. package/corpus/templates/content/changelog/2026-07-17-workspace-switching-now-opens-the-selected-files-database-pr.md +6 -0
  80. package/corpus/templates/content/changelog/2026-07-17-workspaces-now-expand-above-their-own-files-list-without-dup.md +6 -0
  81. package/corpus/templates/content/changelog/2026-07-18-create-named-workspaces-each-with-its-own-private-files-data.md +6 -0
  82. package/corpus/templates/content/changelog/2026-07-18-favorites-align-with-workspace-and-file-rows-in-the-sidebar.md +6 -0
  83. package/corpus/templates/content/changelog/2026-07-18-local-folder-selection-no-longer-invokes-the-unsafe-native-p.md +6 -0
  84. package/corpus/templates/content/changelog/2026-07-18-made-content-workspaces-independently-expandable-restored-or.md +6 -0
  85. package/corpus/templates/content/changelog/2026-07-18-page-details-now-live-in-a-shared-info-and-comments-rail-dat.md +6 -0
  86. package/corpus/templates/content/changelog/2026-07-18-workspace-database-views-now-control-sidebar-workspace-navig.md +6 -0
  87. package/corpus/templates/content/changelog/2026-07-18-workspace-navigation-now-aligns-favorites-with-workspace-pag.md +6 -0
  88. package/corpus/templates/content/changelog/2026-07-19-favorites-now-open-as-a-table-and-compact-breadcrumbs-make-w.md +6 -0
  89. package/corpus/templates/content/changelog/2026-07-19-files-databases-now-start-unfiltered-sidebar-rows-exactly-fo.md +6 -0
  90. package/corpus/templates/content/changelog/2026-07-19-sidebar-page-trees-now-open-only-when-expanded-remember-thei.md +6 -0
  91. package/corpus/templates/content/changelog/2026-07-19-workspace-file-databases-now-use-the-workspace-name-open-as-.md +6 -0
  92. package/corpus/templates/content/changelog/2026-07-19-workspace-navigation-now-stays-stable-on-hover-uses-folder-i.md +6 -0
  93. package/corpus/templates/content/changelog/2026-07-19-workspace-rows-now-use-folder-icons-and-deleting-a-user-crea.md +6 -0
  94. package/corpus/templates/content/changelog/2026-07-19-workspaces-can-be-created-without-leaving-the-workspaces-dat.md +6 -0
  95. package/corpus/templates/content/e2e/global-setup.ts +3 -2
  96. package/corpus/templates/content/parity/matrix.md +28 -28
  97. package/corpus/templates/content/parity/matrix.ts +8 -2
  98. package/corpus/templates/content/server/db/index.ts +1 -0
  99. package/corpus/templates/content/server/db/schema.ts +10 -0
  100. package/corpus/templates/content/server/lib/documents.ts +12 -7
  101. package/corpus/templates/content/server/plugins/db.ts +17 -0
  102. package/corpus/templates/content/shared/api.ts +9 -0
  103. package/corpus/templates/content/shared/database-form.ts +11 -2
  104. package/corpus/templates/content/vite.config.ts +1 -0
  105. package/dist/client/build-compatibility.d.ts +11 -0
  106. package/dist/client/build-compatibility.d.ts.map +1 -0
  107. package/dist/client/build-compatibility.js +56 -0
  108. package/dist/client/build-compatibility.js.map +1 -0
  109. package/dist/client/route-chunk-recovery/index.d.ts +1 -0
  110. package/dist/client/route-chunk-recovery/index.d.ts.map +1 -1
  111. package/dist/client/route-chunk-recovery/index.js +1 -0
  112. package/dist/client/route-chunk-recovery/index.js.map +1 -1
  113. package/dist/client/use-action.d.ts.map +1 -1
  114. package/dist/client/use-action.js +19 -1
  115. package/dist/client/use-action.js.map +1 -1
  116. package/dist/collab/routes.d.ts +1 -1
  117. package/dist/collab/struct-routes.d.ts +1 -1
  118. package/dist/deploy/build.js +2 -1
  119. package/dist/deploy/build.js.map +1 -1
  120. package/dist/file-upload/actions/upload-image.d.ts +1 -1
  121. package/dist/notifications/routes.d.ts +1 -1
  122. package/dist/observability/routes.d.ts +5 -5
  123. package/dist/org/context.d.ts +4 -2
  124. package/dist/org/context.d.ts.map +1 -1
  125. package/dist/org/context.js +44 -22
  126. package/dist/org/context.js.map +1 -1
  127. package/dist/progress/routes.d.ts +1 -1
  128. package/dist/provider-api/actions/custom-provider-registration.d.ts +10 -10
  129. package/dist/provider-api/actions/provider-api.d.ts +12 -12
  130. package/dist/provider-api/corpus-jobs.d.ts +2 -2
  131. package/dist/resources/handlers.d.ts +1 -1
  132. package/dist/secrets/routes.d.ts +9 -9
  133. package/dist/server/action-routes.d.ts.map +1 -1
  134. package/dist/server/action-routes.js +32 -2
  135. package/dist/server/action-routes.js.map +1 -1
  136. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  137. package/dist/server/auth-plugin.d.ts.map +1 -1
  138. package/dist/server/auth-plugin.js +9 -5
  139. package/dist/server/auth-plugin.js.map +1 -1
  140. package/dist/server/better-auth-instance.d.ts.map +1 -1
  141. package/dist/server/better-auth-instance.js +4 -1
  142. package/dist/server/better-auth-instance.js.map +1 -1
  143. package/dist/server/transcribe-voice.d.ts +1 -1
  144. package/dist/shared/mcp-embed-headers.d.ts +1 -1
  145. package/dist/shared/mcp-embed-headers.d.ts.map +1 -1
  146. package/dist/shared/mcp-embed-headers.js +1 -1
  147. package/dist/shared/mcp-embed-headers.js.map +1 -1
  148. package/dist/vite/client.d.ts +6 -0
  149. package/dist/vite/client.d.ts.map +1 -1
  150. package/dist/vite/client.js +8 -0
  151. package/dist/vite/client.js.map +1 -1
  152. package/package.json +1 -1
  153. package/src/client/build-compatibility.ts +77 -0
  154. package/src/client/route-chunk-recovery/index.ts +1 -0
  155. package/src/client/use-action.ts +32 -1
  156. package/src/deploy/build.ts +4 -1
  157. package/src/org/context.ts +56 -30
  158. package/src/server/action-routes.ts +52 -2
  159. package/src/server/auth-plugin.ts +9 -4
  160. package/src/server/better-auth-instance.ts +5 -1
  161. package/src/shared/mcp-embed-headers.ts +1 -1
  162. package/src/vite/client.ts +17 -0
@@ -3,6 +3,7 @@ import {
3
3
  useActionMutation,
4
4
  } from "@agent-native/core/client/hooks";
5
5
  import type {
6
+ ContentDatabaseResponse,
6
7
  ContentDatabaseItem,
7
8
  Document,
8
9
  DocumentCreateRequest,
@@ -20,11 +21,18 @@ import { databaseItemBodyHydrationIsPending } from "@/components/editor/body-hyd
20
21
  import { isEffectivelyEmptyDocumentContent } from "@/components/editor/body-hydration";
21
22
 
22
23
  import type { DocumentUpdateConflictResponse } from "../../actions/update-document";
23
- import { useRestoreContentDatabase } from "./use-content-database";
24
+ import {
25
+ removeOptimisticItemFromContentDatabase,
26
+ useRestoreContentDatabase,
27
+ } from "./use-content-database";
24
28
 
25
29
  export type { DocumentUpdateConflictResponse };
26
30
 
27
- const LIST_DOCUMENTS_QUERY_KEY = ["action", "list-documents", undefined];
31
+ export const LIST_DOCUMENTS_QUERY_KEY = [
32
+ "action",
33
+ "list-documents",
34
+ undefined,
35
+ ] as const;
28
36
 
29
37
  export function documentQueryKey(documentId: string) {
30
38
  return ["action", "get-document", { id: documentId }] as const;
@@ -67,10 +75,18 @@ export function mergeDocumentIntoDocumentCache(
67
75
  export function mergeDocumentIntoListDocumentsCache(
68
76
  old: unknown,
69
77
  document: Document,
78
+ ) {
79
+ return patchDocumentInListDocumentsCache(old, document.id, document);
80
+ }
81
+
82
+ export function patchDocumentInListDocumentsCache(
83
+ old: unknown,
84
+ documentId: string,
85
+ patch: Partial<Document>,
70
86
  ) {
71
87
  if (Array.isArray(old)) {
72
88
  return old.map((item: Document) =>
73
- item.id === document.id ? { ...item, ...document } : item,
89
+ item.id === documentId ? { ...item, ...patch } : item,
74
90
  );
75
91
  }
76
92
 
@@ -79,12 +95,149 @@ export function mergeDocumentIntoListDocumentsCache(
79
95
  if (!Array.isArray(cached.documents)) return old;
80
96
 
81
97
  const nextDocuments = cached.documents.map((item: Document) =>
82
- item.id === document.id ? { ...item, ...document } : item,
98
+ item.id === documentId ? { ...item, ...patch } : item,
83
99
  );
84
100
 
85
101
  return { ...(old as object), documents: nextDocuments };
86
102
  }
87
103
 
104
+ export function setDocumentFavoriteInListCache(
105
+ old: unknown,
106
+ documentId: string,
107
+ isFavorite: boolean,
108
+ ) {
109
+ return patchDocumentInListDocumentsCache(old, documentId, { isFavorite });
110
+ }
111
+
112
+ export function patchDocumentInDatabaseCache(
113
+ current: ContentDatabaseResponse | undefined,
114
+ documentId: string,
115
+ patch: Partial<Document>,
116
+ ): ContentDatabaseResponse | undefined {
117
+ if (!current) return current;
118
+ let changed = false;
119
+ const items = current.items.map((item) => {
120
+ if (item.document.id !== documentId) return item;
121
+ changed = true;
122
+ return {
123
+ ...item,
124
+ document: { ...item.document, ...patch },
125
+ };
126
+ });
127
+ return changed ? { ...current, items } : current;
128
+ }
129
+
130
+ export function setDocumentFavoriteInDatabaseCache(
131
+ current: ContentDatabaseResponse | undefined,
132
+ documentId: string,
133
+ isFavorite: boolean,
134
+ ): ContentDatabaseResponse | undefined {
135
+ if (current?.database?.systemRole === "favorites" && !isFavorite) {
136
+ return removeOptimisticItemFromContentDatabase(current, documentId);
137
+ }
138
+ return patchDocumentInDatabaseCache(current, documentId, { isFavorite });
139
+ }
140
+
141
+ function patchDocumentWithFavoriteMembershipInDatabaseCache(
142
+ current: ContentDatabaseResponse | undefined,
143
+ documentId: string,
144
+ patch: Partial<Document>,
145
+ ): ContentDatabaseResponse | undefined {
146
+ const patched = patchDocumentInDatabaseCache(current, documentId, patch);
147
+ return patch.isFavorite === undefined
148
+ ? patched
149
+ : setDocumentFavoriteInDatabaseCache(patched, documentId, patch.isFavorite);
150
+ }
151
+
152
+ export function patchDocumentCaches(
153
+ queryClient: Pick<QueryClient, "setQueryData" | "setQueriesData">,
154
+ documentId: string,
155
+ patch: Partial<Document>,
156
+ ) {
157
+ queryClient.setQueryData(documentQueryKey(documentId), (old: unknown) =>
158
+ old && typeof old === "object" ? { ...old, ...patch } : old,
159
+ );
160
+ queryClient.setQueryData(LIST_DOCUMENTS_QUERY_KEY, (old: unknown) =>
161
+ patchDocumentInListDocumentsCache(old, documentId, patch),
162
+ );
163
+ queryClient.setQueriesData<ContentDatabaseResponse>(
164
+ { queryKey: ["action", "get-content-database"] },
165
+ (current) =>
166
+ patchDocumentWithFavoriteMembershipInDatabaseCache(
167
+ current,
168
+ documentId,
169
+ patch,
170
+ ),
171
+ );
172
+ }
173
+
174
+ type ContentSpaceNameCache = {
175
+ spaces?: Array<{
176
+ name: string;
177
+ filesDocumentId: string;
178
+ catalogDocumentId: string;
179
+ }>;
180
+ };
181
+
182
+ export function patchContentSpaceNameCaches(
183
+ queryClient: Pick<QueryClient, "setQueriesData"> &
184
+ Parameters<typeof patchDocumentCaches>[0],
185
+ filesDocumentId: string,
186
+ name: string,
187
+ ) {
188
+ const catalogDocumentIds = new Set<string>();
189
+ let matched = false;
190
+
191
+ queryClient.setQueriesData<ContentSpaceNameCache>(
192
+ { queryKey: ["action", "list-content-spaces"] },
193
+ (current) => {
194
+ if (!current?.spaces) return current;
195
+ let cacheMatched = false;
196
+ const spaces = current.spaces.map((space) => {
197
+ if (space.filesDocumentId !== filesDocumentId) return space;
198
+ matched = true;
199
+ cacheMatched = true;
200
+ catalogDocumentIds.add(space.catalogDocumentId);
201
+ return { ...space, name };
202
+ });
203
+ return cacheMatched ? { ...current, spaces } : current;
204
+ },
205
+ );
206
+
207
+ for (const catalogDocumentId of catalogDocumentIds) {
208
+ patchDocumentCaches(queryClient, catalogDocumentId, { title: name });
209
+ }
210
+
211
+ return matched;
212
+ }
213
+
214
+ export function documentUpdateSuccessPatch(
215
+ data: DocumentUpdateResponse,
216
+ variables: DocumentUpdateRequestWithCas,
217
+ ): Partial<Document> {
218
+ return {
219
+ updatedAt: data.updatedAt,
220
+ ...(variables.title !== undefined ? { title: data.title } : {}),
221
+ ...(variables.content !== undefined ? { content: data.content } : {}),
222
+ ...(variables.description !== undefined
223
+ ? { description: data.description }
224
+ : {}),
225
+ ...(variables.icon !== undefined ? { icon: data.icon } : {}),
226
+ ...(variables.isFavorite !== undefined
227
+ ? { isFavorite: data.isFavorite }
228
+ : {}),
229
+ };
230
+ }
231
+
232
+ export function restoreQuerySnapshots(
233
+ queryClient: Pick<QueryClient, "setQueryData">,
234
+ snapshots: Array<[readonly unknown[], unknown]>,
235
+ ) {
236
+ for (const [queryKey, data] of snapshots) {
237
+ queryClient.setQueryData(queryKey, data);
238
+ }
239
+ }
240
+
88
241
  export function seedDatabaseItemDocumentCaches(
89
242
  queryClient: Pick<QueryClient, "getQueryData" | "setQueryData">,
90
243
  item: ContentDatabaseItem,
@@ -201,7 +354,65 @@ export function useUpdateDocument() {
201
354
  return useActionMutation<DocumentUpdateResult, DocumentUpdateRequestWithCas>(
202
355
  "update-document",
203
356
  {
204
- onSuccess: (data, variables) => {
357
+ skipActionQueryInvalidation: true,
358
+ onMutate: async (variables) => {
359
+ const optimisticPatch: Partial<Document> = {
360
+ ...(variables.title !== undefined ? { title: variables.title } : {}),
361
+ ...(variables.icon !== undefined ? { icon: variables.icon } : {}),
362
+ ...(variables.isFavorite !== undefined
363
+ ? { isFavorite: variables.isFavorite }
364
+ : {}),
365
+ };
366
+ if (Object.keys(optimisticPatch).length === 0) return undefined;
367
+
368
+ const documentKey = documentQueryKey(variables.id);
369
+ const databaseFilter = {
370
+ queryKey: ["action", "get-content-database"],
371
+ } as const;
372
+ const contentSpacesFilter = {
373
+ queryKey: ["action", "list-content-spaces"],
374
+ } as const;
375
+ await Promise.all([
376
+ queryClient.cancelQueries({ queryKey: documentKey }),
377
+ queryClient.cancelQueries({ queryKey: LIST_DOCUMENTS_QUERY_KEY }),
378
+ queryClient.cancelQueries(databaseFilter),
379
+ queryClient.cancelQueries(contentSpacesFilter),
380
+ ]);
381
+
382
+ const previous: Array<[readonly unknown[], unknown]> = [
383
+ [documentKey, queryClient.getQueryData(documentKey)],
384
+ [
385
+ LIST_DOCUMENTS_QUERY_KEY,
386
+ queryClient.getQueryData(LIST_DOCUMENTS_QUERY_KEY),
387
+ ],
388
+ ...queryClient.getQueriesData<ContentDatabaseResponse>(
389
+ databaseFilter,
390
+ ),
391
+ ...queryClient.getQueriesData(contentSpacesFilter),
392
+ ];
393
+
394
+ patchDocumentCaches(queryClient, variables.id, optimisticPatch);
395
+ const renamedContentSpace =
396
+ variables.title !== undefined
397
+ ? patchContentSpaceNameCaches(
398
+ queryClient,
399
+ variables.id,
400
+ variables.title,
401
+ )
402
+ : false;
403
+
404
+ return { previous, renamedContentSpace };
405
+ },
406
+ onError: (_error, variables, context) => {
407
+ const rollback = context as
408
+ | { previous?: Array<[readonly unknown[], unknown]> }
409
+ | undefined;
410
+ restoreQuerySnapshots(queryClient, rollback?.previous ?? []);
411
+ },
412
+ onSuccess: (data, variables, context) => {
413
+ const renamedContentSpace = (
414
+ context as { renamedContentSpace?: boolean } | undefined
415
+ )?.renamedContentSpace;
205
416
  // A CAS conflict is a normal (non-thrown) result, not a successful
206
417
  // save — converge the caches to the returned server document (so the
207
418
  // UI immediately reflects the write that actually won) but skip the
@@ -217,6 +428,28 @@ export function useUpdateDocument() {
217
428
  queryClient.setQueryData(LIST_DOCUMENTS_QUERY_KEY, (old: unknown) =>
218
429
  mergeDocumentIntoListDocumentsCache(old, serverDocument),
219
430
  );
431
+ queryClient.setQueriesData<ContentDatabaseResponse>(
432
+ { queryKey: ["action", "get-content-database"] },
433
+ (current) =>
434
+ patchDocumentWithFavoriteMembershipInDatabaseCache(
435
+ current,
436
+ variables.id,
437
+ serverDocument,
438
+ ),
439
+ );
440
+ if (renamedContentSpace) {
441
+ patchContentSpaceNameCaches(
442
+ queryClient,
443
+ variables.id,
444
+ serverDocument.title,
445
+ );
446
+ queryClient.invalidateQueries({
447
+ queryKey: ["action", "list-content-spaces"],
448
+ });
449
+ queryClient.invalidateQueries({
450
+ queryKey: ["action", "get-content-database"],
451
+ });
452
+ }
220
453
  queryClient.invalidateQueries({
221
454
  queryKey: ["action", "get-document", { id: variables.id }],
222
455
  });
@@ -226,21 +459,33 @@ export function useUpdateDocument() {
226
459
  return;
227
460
  }
228
461
 
229
- queryClient.setQueryData(
230
- ["action", "get-document", { id: variables.id }],
231
- (old: unknown) => mergeDocumentIntoDocumentCache(old, data),
462
+ patchDocumentCaches(
463
+ queryClient,
464
+ variables.id,
465
+ documentUpdateSuccessPatch(data, variables),
232
466
  );
233
- queryClient.setQueryData(LIST_DOCUMENTS_QUERY_KEY, (old: unknown) =>
234
- mergeDocumentIntoListDocumentsCache(old, data),
235
- );
236
- queryClient.invalidateQueries({
237
- queryKey: ["action", "get-document", { id: variables.id }],
238
- });
239
- queryClient.invalidateQueries({
240
- queryKey: ["action", "list-documents"],
241
- });
467
+ if (renamedContentSpace) {
468
+ patchContentSpaceNameCaches(queryClient, variables.id, data.title);
469
+ queryClient.invalidateQueries({
470
+ queryKey: ["action", "list-content-spaces"],
471
+ });
472
+ queryClient.invalidateQueries({
473
+ queryKey: ["action", "get-content-database"],
474
+ });
475
+ }
476
+ if (variables.isFavorite !== undefined) {
477
+ queryClient.invalidateQueries({
478
+ queryKey: ["action", "get-content-database"],
479
+ });
480
+ }
242
481
 
243
482
  if (data.softDeletedDatabaseIds.length > 0) {
483
+ queryClient.invalidateQueries({
484
+ queryKey: ["action", "get-content-database"],
485
+ });
486
+ queryClient.invalidateQueries({
487
+ queryKey: ["action", "list-trashed-content-databases"],
488
+ });
244
489
  const databaseIds = data.softDeletedDatabaseIds;
245
490
  toast("Database deleted", {
246
491
  action: {
@@ -270,8 +515,8 @@ export function useUpdateDocument() {
270
515
  export function useDeleteDocument() {
271
516
  const queryClient = useQueryClient();
272
517
  return useActionMutation<
273
- { success: boolean; deleted: number },
274
- { id: string }
518
+ { success: boolean; deleted: number; removed?: number },
519
+ { id: string; databaseDocumentId?: string }
275
520
  >("delete-document", {
276
521
  onSuccess: (_data, variables) => {
277
522
  queryClient.invalidateQueries({
@@ -280,6 +525,12 @@ export function useDeleteDocument() {
280
525
  queryClient.invalidateQueries({
281
526
  queryKey: ["action", "get-document", { id: variables.id }],
282
527
  });
528
+ queryClient.invalidateQueries({
529
+ queryKey: ["action", "get-content-database"],
530
+ });
531
+ queryClient.invalidateQueries({
532
+ queryKey: ["action", "list-content-spaces"],
533
+ });
283
534
  queryClient.invalidateQueries({
284
535
  queryKey: ["action", "list-trashed-content-databases"],
285
536
  });