@arbidocs/react 0.5.141 → 0.5.143
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/databases.js +18 -2
- package/dist/databases.js.map +2 -2
- package/dist/index.cjs +43 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +152 -22
- package/dist/notifications/notification-types.js +5 -0
- package/dist/notifications/notification-types.js.map +2 -2
- package/dist/notifications/server-notifications.js +21 -0
- package/dist/notifications/server-notifications.js.map +2 -2
- package/package.json +3 -3
package/dist/databases.js
CHANGED
|
@@ -28,6 +28,7 @@ function useInvalidate() {
|
|
|
28
28
|
function openWorkspaceId(arbi) {
|
|
29
29
|
return arbi.hasWorkspace ? arbi.getWorkspaceId() : "";
|
|
30
30
|
}
|
|
31
|
+
const DATABASES_OPEN_VIEW = "databases.open";
|
|
31
32
|
function useDatabases() {
|
|
32
33
|
const arbi = useArbi();
|
|
33
34
|
const workspaceId = openWorkspaceId(arbi);
|
|
@@ -109,11 +110,24 @@ function useAddDatabaseRows() {
|
|
|
109
110
|
return useMutation({
|
|
110
111
|
mutationFn: ({
|
|
111
112
|
databaseId,
|
|
112
|
-
rows
|
|
113
|
-
|
|
113
|
+
rows,
|
|
114
|
+
shared
|
|
115
|
+
}) => arbi.databases.addRows(databaseId, rows, shared === false ? { shared } : void 0),
|
|
114
116
|
onSuccess: () => Promise.all([invalidate.rows(), invalidate.list()])
|
|
115
117
|
});
|
|
116
118
|
}
|
|
119
|
+
function useShareDatabaseRow() {
|
|
120
|
+
const arbi = useArbi();
|
|
121
|
+
const invalidate = useInvalidate();
|
|
122
|
+
return useMutation({
|
|
123
|
+
mutationFn: ({
|
|
124
|
+
databaseId,
|
|
125
|
+
rowId,
|
|
126
|
+
shared = true
|
|
127
|
+
}) => arbi.databases.shareRow(databaseId, rowId, shared),
|
|
128
|
+
onSuccess: () => invalidate.rows()
|
|
129
|
+
});
|
|
130
|
+
}
|
|
117
131
|
function useUpdateDatabaseRow() {
|
|
118
132
|
const arbi = useArbi();
|
|
119
133
|
const queryClient = useQueryClient();
|
|
@@ -175,6 +189,7 @@ function useExportDatabase() {
|
|
|
175
189
|
);
|
|
176
190
|
}
|
|
177
191
|
export {
|
|
192
|
+
DATABASES_OPEN_VIEW,
|
|
178
193
|
DATABASE_RELATION_PICK_LIMIT,
|
|
179
194
|
DATABASE_ROWS_PAGE,
|
|
180
195
|
useAddDatabaseRows,
|
|
@@ -189,6 +204,7 @@ export {
|
|
|
189
204
|
useImportDatabase,
|
|
190
205
|
useImportDatabaseRows,
|
|
191
206
|
useSearchDatabaseRows,
|
|
207
|
+
useShareDatabaseRow,
|
|
192
208
|
useUpdateDatabase,
|
|
193
209
|
useUpdateDatabaseRow
|
|
194
210
|
};
|
package/dist/databases.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/databases.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Databases: user-defined tables of the open workspace (a client database, billing records),\n * encrypted under the workspace key like facts. The list also carries databases of public\n * workspaces, which come back `editable: false` (read here, edited from their own workspace).\n *\n * Reads are keyed by the one key factory (`arbiQueryKeys.database*`); every write keeps those\n * entries current.\n */\n\nimport { useCallback } from 'react'\nimport { useMutation, useQuery, useQueryClient, type QueryClient } from '@tanstack/react-query'\nimport type {\n Database,\n DatabaseColumnWrite,\n DatabaseImportResult,\n DatabaseRow,\n DatabaseRowPage,\n} from '@arbidocs/sdk/browser'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from './useArbi'\nimport { arbiQueryKeys } from './query-keys'\n\nexport type { Database, DatabaseColumnWrite, DatabaseImportResult, DatabaseRow, DatabaseRowPage }\nexport type { DatabaseColumn } from '@arbidocs/sdk/browser'\n\ntype DatabaseCreate = components['schemas']['DatabaseCreate']\ntype DatabaseUpdate = components['schemas']['DatabaseUpdate']\ntype DatabaseRowValues = components['schemas']['DatabaseRowWrite']['values']\nexport type DatabaseAggregateRequest = components['schemas']['DatabaseAggregateRequest']\nexport type DatabaseAggregateResult = components['schemas']['DatabaseAggregateResult']\n\n/** The most rows the grid loads at once (the API's page limit). Search runs on the server. */\nexport const DATABASE_ROWS_PAGE = 1000\n\n/** The most rows a relation cell's picker lists for one search. */\nexport const DATABASE_RELATION_PICK_LIMIT = 50\n\n/**\n * After a relation cell changes, other databases' rows can have changed with it (the paired column\n * of a two-way relation, lookups and rollups reading through it): refetch them when next shown.\n * The edited database's own rows are left alone (the grid already holds the server's answer)\n * unless the relation links it to itself.\n */\nfunction invalidateRelatedRows(queryClient: QueryClient, databaseId: string, includeSelf: boolean) {\n return queryClient.invalidateQueries({\n queryKey: arbiQueryKeys.databaseRows(),\n // ['arbi', 'databases', 'rows', workspaceId, databaseId, params]\n predicate: (query) => includeSelf || query.queryKey[4] !== databaseId,\n })\n}\n\n/** Whether a cached key (`['arbi', 'databases', kind, workspaceId, \u2026]`) is this workspace's. */\nfunction sameWorkspace(queryKey: readonly unknown[] | undefined, workspaceId: string): boolean {\n return !!queryKey && queryKey[3] === workspaceId\n}\n\nfunction useInvalidate() {\n const queryClient = useQueryClient()\n return {\n list: () => queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseList() }),\n rows: () =>\n Promise.all([\n queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseRows() }),\n queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseAggregate() }),\n ]),\n all: () => queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databases() }),\n }\n}\n\n/** The open workspace's id, or '' with none open. */\nfunction openWorkspaceId(arbi: ReturnType<typeof useArbi>): string {\n return arbi.hasWorkspace ? arbi.getWorkspaceId() : ''\n}\n\n/**\n * The open workspace's databases, then those of public workspaces (read-only here). Kept per\n * workspace, and read only while that workspace stays open on the server (the list is the open\n * workspace's there): a read that crosses a switch is dropped, never cached as the other's.\n */\nexport function useDatabases() {\n const arbi = useArbi()\n const workspaceId = openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.databaseList(workspaceId),\n queryFn: () => arbi.readInWorkspace(workspaceId, () => arbi.databases.list()),\n enabled: !!workspaceId,\n staleTime: 1000 * 30,\n })\n}\n\n/** `workspaceId`: the database's own workspace (a by-id read acts there), else the open one. */\nexport function useDatabase(databaseId: string | null, options?: { workspaceId?: string }) {\n const arbi = useArbi()\n const workspaceId = options?.workspaceId ?? openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.database(workspaceId, databaseId ?? ''),\n queryFn: () => arbi.databases.get(databaseId as string),\n enabled: !!workspaceId && Boolean(databaseId),\n staleTime: 1000 * 30,\n })\n}\n\n/** A database's rows: searched (any cell) on the server, the first `DATABASE_ROWS_PAGE`. */\nexport function useDatabaseRows(\n databaseId: string | null,\n q: string,\n options?: { workspaceId?: string }\n) {\n const arbi = useArbi()\n const workspaceId = options?.workspaceId ?? openWorkspaceId(arbi)\n const query = { q: q.trim() || undefined, limit: DATABASE_ROWS_PAGE }\n return useQuery({\n queryKey: arbiQueryKeys.databaseRows(workspaceId, databaseId ?? '', query),\n queryFn: () => arbi.databases.rows(databaseId as string, query),\n enabled: !!workspaceId && Boolean(databaseId),\n staleTime: 1000 * 15,\n // What was shown stays while the next search loads, never another workspace's rows.\n placeholderData: (previous, previousQuery) =>\n sameWorkspace(previousQuery?.queryKey, workspaceId) ? previous : undefined,\n })\n}\n\n/**\n * A database's rows grouped and measured on the server (over every row): the labels and series a\n * chart or a metric tile draws. Row writes here refresh it.\n */\nexport function useDatabaseAggregate(\n databaseId: string | null,\n request: Partial<DatabaseAggregateRequest>,\n options?: { enabled?: boolean; workspaceId?: string }\n) {\n const arbi = useArbi()\n const workspaceId = options?.workspaceId ?? openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.databaseAggregate(workspaceId, databaseId ?? '', request),\n queryFn: () => arbi.databases.aggregate(databaseId as string, request),\n enabled: (options?.enabled ?? true) && !!workspaceId && Boolean(databaseId),\n staleTime: 1000 * 15,\n placeholderData: (previous, previousQuery) =>\n sameWorkspace(previousQuery?.queryKey, workspaceId) ? previous : undefined,\n })\n}\n\n/**\n * Search a database's rows (any cell, on the server) for a relation cell's picker. Read once per\n * search rather than cached: the picker debounces its typing.\n */\nexport function useSearchDatabaseRows() {\n const arbi = useArbi()\n return useCallback(\n (databaseId: string, q: string): Promise<DatabaseRow[]> =>\n arbi.databases\n .rows(databaseId, { q: q.trim() || undefined, limit: DATABASE_RELATION_PICK_LIMIT })\n .then((page) => page.rows),\n [arbi]\n )\n}\n\nexport function useCreateDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: (body: DatabaseCreate) => arbi.databases.create(body),\n onSuccess: () => invalidate.list(),\n })\n}\n\n/** Rename, describe, or change columns (`columns` is the full new list). */\nexport function useUpdateDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ databaseId, patch }: { databaseId: string; patch: DatabaseUpdate }) =>\n arbi.databases.update(databaseId, patch),\n onSuccess: () => invalidate.all(),\n })\n}\n\nexport function useDeleteDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: (databaseId: string) => arbi.databases.delete(databaseId),\n onSuccess: () => invalidate.list(),\n })\n}\n\nexport function useAddDatabaseRows() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({\n databaseId,\n rows,\n }: {\n databaseId: string\n rows: { values: DatabaseRowValues }[]\n }) => arbi.databases.addRows(databaseId, rows),\n onSuccess: () => Promise.all([invalidate.rows(), invalidate.list()]),\n })\n}\n\n/**\n * Change cells of one row (`null` empties a cell). The server's (normalised) row replaces the row in\n * every cached page of rows. Other databases are marked stale for relation/lookups/rollups;\n * the edited database is re-read for a self-relation or unknown column metadata. Failed edits\n * re-read rows to reconcile.\n */\nexport function useUpdateDatabaseRow() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const workspaceId = openWorkspaceId(arbi)\n return useMutation({\n mutationFn: ({\n databaseId,\n rowId,\n values,\n }: {\n databaseId: string\n rowId: string\n values: DatabaseRowValues\n }) => arbi.databases.updateRow(databaseId, rowId, values),\n onSuccess: (saved, { databaseId, values }) => {\n queryClient.setQueriesData<DatabaseRowPage>(\n { queryKey: arbiQueryKeys.databaseRows() },\n (page) =>\n page && { ...page, rows: page.rows.map((row) => (row.id === saved.id ? saved : row)) }\n )\n const database = queryClient.getQueryData<Database>(\n arbiQueryKeys.database(workspaceId, databaseId)\n )\n const selfLinked =\n !database?.columns ||\n database.columns.some(\n (column) =>\n column.id in (values ?? {}) &&\n column.type === 'relation' &&\n column.relation?.database_id === databaseId\n )\n void invalidateRelatedRows(queryClient, databaseId, selfLinked)\n // Every chart over a database can read through the edited cell (relations, lookups).\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseAggregate() })\n },\n onError: () => {\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseRows() })\n },\n })\n}\n\nexport function useDeleteDatabaseRows() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ databaseId, ids }: { databaseId: string; ids: string[] }) =>\n arbi.databases.deleteRows(databaseId, ids),\n onSuccess: () => Promise.all([invalidate.rows(), invalidate.list()]),\n })\n}\n\n/** Create a database from a .csv / .xlsx file (column types are inferred). */\nexport function useImportDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ file, name }: { file: File; name?: string }) =>\n arbi.databases.import(file, name),\n onSuccess: () => invalidate.list(),\n })\n}\n\n/** Append a spreadsheet's rows; headers match column names, unknown ones become new columns. */\nexport function useImportDatabaseRows() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ databaseId, file }: { databaseId: string; file: File }) =>\n arbi.databases.importRows(databaseId, file),\n onSuccess: () => invalidate.all(),\n })\n}\n\n/** Download a database as .xlsx or .csv. */\nexport function useExportDatabase() {\n const arbi = useArbi()\n return useCallback(\n (databaseId: string, format: 'csv' | 'xlsx') => arbi.databases.export(databaseId, format),\n [arbi]\n )\n}\n"],
|
|
5
|
-
"mappings": "AASA,SAAS,mBAAmB;AAC5B,SAAS,aAAa,UAAU,sBAAwC;AASxE,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAYvB,MAAM,qBAAqB;AAG3B,MAAM,+BAA+B;AAQ5C,SAAS,sBAAsB,aAA0B,YAAoB,aAAsB;AACjG,SAAO,YAAY,kBAAkB;AAAA,IACnC,UAAU,cAAc,aAAa;AAAA;AAAA,IAErC,WAAW,CAAC,UAAU,eAAe,MAAM,SAAS,CAAC,MAAM;AAAA,EAC7D,CAAC;AACH;AAGA,SAAS,cAAc,UAA0C,aAA8B;AAC7F,SAAO,CAAC,CAAC,YAAY,SAAS,CAAC,MAAM;AACvC;AAEA,SAAS,gBAAgB;AACvB,QAAM,cAAc,eAAe;AACnC,SAAO;AAAA,IACL,MAAM,MAAM,YAAY,kBAAkB,EAAE,UAAU,cAAc,aAAa,EAAE,CAAC;AAAA,IACpF,MAAM,MACJ,QAAQ,IAAI;AAAA,MACV,YAAY,kBAAkB,EAAE,UAAU,cAAc,aAAa,EAAE,CAAC;AAAA,MACxE,YAAY,kBAAkB,EAAE,UAAU,cAAc,kBAAkB,EAAE,CAAC;AAAA,IAC/E,CAAC;AAAA,IACH,KAAK,MAAM,YAAY,kBAAkB,EAAE,UAAU,cAAc,UAAU,EAAE,CAAC;AAAA,EAClF;AACF;AAGA,SAAS,gBAAgB,MAA0C;AACjE,SAAO,KAAK,eAAe,KAAK,eAAe,IAAI;AACrD;
|
|
4
|
+
"sourcesContent": ["/**\n * Databases: user-defined tables of the open workspace (a client database, billing records),\n * encrypted under the workspace key like facts. The list also carries databases of public\n * workspaces, which come back `editable: false` (read here, edited from their own workspace).\n *\n * Reads are keyed by the one key factory (`arbiQueryKeys.database*`); every write keeps those\n * entries current.\n */\n\nimport { useCallback } from 'react'\nimport { useMutation, useQuery, useQueryClient, type QueryClient } from '@tanstack/react-query'\nimport type {\n Database,\n DatabaseColumnWrite,\n DatabaseImportResult,\n DatabaseRow,\n DatabaseRowPage,\n} from '@arbidocs/sdk/browser'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from './useArbi'\nimport { arbiQueryKeys } from './query-keys'\n\nexport type { Database, DatabaseColumnWrite, DatabaseImportResult, DatabaseRow, DatabaseRowPage }\nexport type { DatabaseColumn } from '@arbidocs/sdk/browser'\n\ntype DatabaseCreate = components['schemas']['DatabaseCreate']\ntype DatabaseUpdate = components['schemas']['DatabaseUpdate']\ntype DatabaseRowValues = components['schemas']['DatabaseRowWrite']['values']\nexport type DatabaseAggregateRequest = components['schemas']['DatabaseAggregateRequest']\nexport type DatabaseAggregateResult = components['schemas']['DatabaseAggregateResult']\n\n/** The most rows the grid loads at once (the API's page limit). Search runs on the server. */\nexport const DATABASE_ROWS_PAGE = 1000\n\n/** The most rows a relation cell's picker lists for one search. */\nexport const DATABASE_RELATION_PICK_LIMIT = 50\n\n/**\n * After a relation cell changes, other databases' rows can have changed with it (the paired column\n * of a two-way relation, lookups and rollups reading through it): refetch them when next shown.\n * The edited database's own rows are left alone (the grid already holds the server's answer)\n * unless the relation links it to itself.\n */\nfunction invalidateRelatedRows(queryClient: QueryClient, databaseId: string, includeSelf: boolean) {\n return queryClient.invalidateQueries({\n queryKey: arbiQueryKeys.databaseRows(),\n // ['arbi', 'databases', 'rows', workspaceId, databaseId, params]\n predicate: (query) => includeSelf || query.queryKey[4] !== databaseId,\n })\n}\n\n/** Whether a cached key (`['arbi', 'databases', kind, workspaceId, \u2026]`) is this workspace's. */\nfunction sameWorkspace(queryKey: readonly unknown[] | undefined, workspaceId: string): boolean {\n return !!queryKey && queryKey[3] === workspaceId\n}\n\nfunction useInvalidate() {\n const queryClient = useQueryClient()\n return {\n list: () => queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseList() }),\n rows: () =>\n Promise.all([\n queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseRows() }),\n queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseAggregate() }),\n ]),\n all: () => queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databases() }),\n }\n}\n\n/** The open workspace's id, or '' with none open. */\nfunction openWorkspaceId(arbi: ReturnType<typeof useArbi>): string {\n return arbi.hasWorkspace ? arbi.getWorkspaceId() : ''\n}\n\n/** The transient view a host sets to open the databases page at one database (and row): an approval\n * step's request, a notification about a row. */\nexport const DATABASES_OPEN_VIEW = 'databases.open'\n\nexport interface DatabaseOpenRequest {\n databaseId: string\n rowId?: string\n}\n\n/**\n * The open workspace's databases, then those of public workspaces (read-only here). Kept per\n * workspace, and read only while that workspace stays open on the server (the list is the open\n * workspace's there): a read that crosses a switch is dropped, never cached as the other's.\n */\nexport function useDatabases() {\n const arbi = useArbi()\n const workspaceId = openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.databaseList(workspaceId),\n queryFn: () => arbi.readInWorkspace(workspaceId, () => arbi.databases.list()),\n enabled: !!workspaceId,\n staleTime: 1000 * 30,\n })\n}\n\n/** `workspaceId`: the database's own workspace (a by-id read acts there), else the open one. */\nexport function useDatabase(databaseId: string | null, options?: { workspaceId?: string }) {\n const arbi = useArbi()\n const workspaceId = options?.workspaceId ?? openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.database(workspaceId, databaseId ?? ''),\n queryFn: () => arbi.databases.get(databaseId as string),\n enabled: !!workspaceId && Boolean(databaseId),\n staleTime: 1000 * 30,\n })\n}\n\n/** A database's rows: searched (any cell) on the server, the first `DATABASE_ROWS_PAGE`. */\nexport function useDatabaseRows(\n databaseId: string | null,\n q: string,\n options?: { workspaceId?: string }\n) {\n const arbi = useArbi()\n const workspaceId = options?.workspaceId ?? openWorkspaceId(arbi)\n const query = { q: q.trim() || undefined, limit: DATABASE_ROWS_PAGE }\n return useQuery({\n queryKey: arbiQueryKeys.databaseRows(workspaceId, databaseId ?? '', query),\n queryFn: () => arbi.databases.rows(databaseId as string, query),\n enabled: !!workspaceId && Boolean(databaseId),\n staleTime: 1000 * 15,\n // What was shown stays while the next search loads, never another workspace's rows.\n placeholderData: (previous, previousQuery) =>\n sameWorkspace(previousQuery?.queryKey, workspaceId) ? previous : undefined,\n })\n}\n\n/**\n * A database's rows grouped and measured on the server (over every row): the labels and series a\n * chart or a metric tile draws. Row writes here refresh it.\n */\nexport function useDatabaseAggregate(\n databaseId: string | null,\n request: Partial<DatabaseAggregateRequest>,\n options?: { enabled?: boolean; workspaceId?: string }\n) {\n const arbi = useArbi()\n const workspaceId = options?.workspaceId ?? openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.databaseAggregate(workspaceId, databaseId ?? '', request),\n queryFn: () => arbi.databases.aggregate(databaseId as string, request),\n enabled: (options?.enabled ?? true) && !!workspaceId && Boolean(databaseId),\n staleTime: 1000 * 15,\n placeholderData: (previous, previousQuery) =>\n sameWorkspace(previousQuery?.queryKey, workspaceId) ? previous : undefined,\n })\n}\n\n/**\n * Search a database's rows (any cell, on the server) for a relation cell's picker. Read once per\n * search rather than cached: the picker debounces its typing.\n */\nexport function useSearchDatabaseRows() {\n const arbi = useArbi()\n return useCallback(\n (databaseId: string, q: string): Promise<DatabaseRow[]> =>\n arbi.databases\n .rows(databaseId, { q: q.trim() || undefined, limit: DATABASE_RELATION_PICK_LIMIT })\n .then((page) => page.rows),\n [arbi]\n )\n}\n\nexport function useCreateDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: (body: DatabaseCreate) => arbi.databases.create(body),\n onSuccess: () => invalidate.list(),\n })\n}\n\n/** Rename, describe, or change columns (`columns` is the full new list). */\nexport function useUpdateDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ databaseId, patch }: { databaseId: string; patch: DatabaseUpdate }) =>\n arbi.databases.update(databaseId, patch),\n onSuccess: () => invalidate.all(),\n })\n}\n\nexport function useDeleteDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: (databaseId: string) => arbi.databases.delete(databaseId),\n onSuccess: () => invalidate.list(),\n })\n}\n\nexport function useAddDatabaseRows() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({\n databaseId,\n rows,\n shared,\n }: {\n databaseId: string\n rows: { values: DatabaseRowValues }[]\n /** False: the caller's private drafts until submitted (`useShareDatabaseRow`). */\n shared?: boolean\n }) => arbi.databases.addRows(databaseId, rows, shared === false ? { shared } : undefined),\n onSuccess: () => Promise.all([invalidate.rows(), invalidate.list()]),\n })\n}\n\n/**\n * Submit a draft row (share it with the workspace: its approvers are told), or, as a workspace owner,\n * make a shared row private again (`shared: false`).\n */\nexport function useShareDatabaseRow() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({\n databaseId,\n rowId,\n shared = true,\n }: {\n databaseId: string\n rowId: string\n shared?: boolean\n }) => arbi.databases.shareRow(databaseId, rowId, shared),\n onSuccess: () => invalidate.rows(),\n })\n}\n\n/**\n * Change cells of one row (`null` empties a cell). The server's (normalised) row replaces the row in\n * every cached page of rows. Other databases are marked stale for relation/lookups/rollups;\n * the edited database is re-read for a self-relation or unknown column metadata. Failed edits\n * re-read rows to reconcile.\n */\nexport function useUpdateDatabaseRow() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const workspaceId = openWorkspaceId(arbi)\n return useMutation({\n mutationFn: ({\n databaseId,\n rowId,\n values,\n }: {\n databaseId: string\n rowId: string\n values: DatabaseRowValues\n }) => arbi.databases.updateRow(databaseId, rowId, values),\n onSuccess: (saved, { databaseId, values }) => {\n queryClient.setQueriesData<DatabaseRowPage>(\n { queryKey: arbiQueryKeys.databaseRows() },\n (page) =>\n page && { ...page, rows: page.rows.map((row) => (row.id === saved.id ? saved : row)) }\n )\n const database = queryClient.getQueryData<Database>(\n arbiQueryKeys.database(workspaceId, databaseId)\n )\n const selfLinked =\n !database?.columns ||\n database.columns.some(\n (column) =>\n column.id in (values ?? {}) &&\n column.type === 'relation' &&\n column.relation?.database_id === databaseId\n )\n void invalidateRelatedRows(queryClient, databaseId, selfLinked)\n // Every chart over a database can read through the edited cell (relations, lookups).\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseAggregate() })\n },\n onError: () => {\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.databaseRows() })\n },\n })\n}\n\nexport function useDeleteDatabaseRows() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ databaseId, ids }: { databaseId: string; ids: string[] }) =>\n arbi.databases.deleteRows(databaseId, ids),\n onSuccess: () => Promise.all([invalidate.rows(), invalidate.list()]),\n })\n}\n\n/** Create a database from a .csv / .xlsx file (column types are inferred). */\nexport function useImportDatabase() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ file, name }: { file: File; name?: string }) =>\n arbi.databases.import(file, name),\n onSuccess: () => invalidate.list(),\n })\n}\n\n/** Append a spreadsheet's rows; headers match column names, unknown ones become new columns. */\nexport function useImportDatabaseRows() {\n const arbi = useArbi()\n const invalidate = useInvalidate()\n return useMutation({\n mutationFn: ({ databaseId, file }: { databaseId: string; file: File }) =>\n arbi.databases.importRows(databaseId, file),\n onSuccess: () => invalidate.all(),\n })\n}\n\n/** Download a database as .xlsx or .csv. */\nexport function useExportDatabase() {\n const arbi = useArbi()\n return useCallback(\n (databaseId: string, format: 'csv' | 'xlsx') => arbi.databases.export(databaseId, format),\n [arbi]\n )\n}\n"],
|
|
5
|
+
"mappings": "AASA,SAAS,mBAAmB;AAC5B,SAAS,aAAa,UAAU,sBAAwC;AASxE,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAYvB,MAAM,qBAAqB;AAG3B,MAAM,+BAA+B;AAQ5C,SAAS,sBAAsB,aAA0B,YAAoB,aAAsB;AACjG,SAAO,YAAY,kBAAkB;AAAA,IACn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;AACrB,QAAM,aAAa,cAAc;AACjC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,EAAE,MAAM,KAAK,MACxB,KAAK,UAAU,OAAO,MAAM,IAAI;AAAA,IAClC,WAAW,MAAM,WAAW,KAAK;AAAA,EACnC,CAAC;AACH;AAGO,SAAS,wBAAwB;AACtC,QAAM,OAAO,QAAQ;AACrB,QAAM,aAAa,cAAc;AACjC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,EAAE,YAAY,KAAK,MAC9B,KAAK,UAAU,WAAW,YAAY,IAAI;AAAA,IAC5C,WAAW,MAAM,WAAW,IAAI;AAAA,EAClC,CAAC;AACH;AAGO,SAAS,oBAAoB;AAClC,QAAM,OAAO,QAAQ;AACrB,SAAO;AAAA,IACL,CAAC,YAAoB,WAA2B,KAAK,UAAU,OAAO,YAAY,MAAM;AAAA,IACxF,CAAC,IAAI;AAAA,EACP;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -9898,6 +9898,7 @@ function useInvalidate() {
|
|
|
9898
9898
|
function openWorkspaceId2(arbi) {
|
|
9899
9899
|
return arbi.hasWorkspace ? arbi.getWorkspaceId() : "";
|
|
9900
9900
|
}
|
|
9901
|
+
var DATABASES_OPEN_VIEW = "databases.open";
|
|
9901
9902
|
function useDatabases() {
|
|
9902
9903
|
const arbi = chunkFE6ZSNZE_cjs.useArbi();
|
|
9903
9904
|
const workspaceId = openWorkspaceId2(arbi);
|
|
@@ -9979,11 +9980,24 @@ function useAddDatabaseRows() {
|
|
|
9979
9980
|
return reactQuery.useMutation({
|
|
9980
9981
|
mutationFn: ({
|
|
9981
9982
|
databaseId,
|
|
9982
|
-
rows
|
|
9983
|
-
|
|
9983
|
+
rows,
|
|
9984
|
+
shared
|
|
9985
|
+
}) => arbi.databases.addRows(databaseId, rows, shared === false ? { shared } : void 0),
|
|
9984
9986
|
onSuccess: () => Promise.all([invalidate.rows(), invalidate.list()])
|
|
9985
9987
|
});
|
|
9986
9988
|
}
|
|
9989
|
+
function useShareDatabaseRow() {
|
|
9990
|
+
const arbi = chunkFE6ZSNZE_cjs.useArbi();
|
|
9991
|
+
const invalidate = useInvalidate();
|
|
9992
|
+
return reactQuery.useMutation({
|
|
9993
|
+
mutationFn: ({
|
|
9994
|
+
databaseId,
|
|
9995
|
+
rowId,
|
|
9996
|
+
shared = true
|
|
9997
|
+
}) => arbi.databases.shareRow(databaseId, rowId, shared),
|
|
9998
|
+
onSuccess: () => invalidate.rows()
|
|
9999
|
+
});
|
|
10000
|
+
}
|
|
9987
10001
|
function useUpdateDatabaseRow() {
|
|
9988
10002
|
const arbi = chunkFE6ZSNZE_cjs.useArbi();
|
|
9989
10003
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -15769,6 +15783,10 @@ function getNotificationTypeMeta(type) {
|
|
|
15769
15783
|
return { Icon: lucideReact.PenLine, iconClassName: "text-green-600", label: "Signed" };
|
|
15770
15784
|
case "signature_declined":
|
|
15771
15785
|
return { Icon: lucideReact.PenLine, iconClassName: "text-orange-500", label: "Declined" };
|
|
15786
|
+
case "database_row_submitted":
|
|
15787
|
+
return { Icon: lucideReact.Stamp, iconClassName: "text-primary", label: "Approval" };
|
|
15788
|
+
case "database_row_decided":
|
|
15789
|
+
return { Icon: lucideReact.Stamp, iconClassName: "text-green-600", label: "Decision" };
|
|
15772
15790
|
case "thread_reply":
|
|
15773
15791
|
return { Icon: lucideReact.Reply, iconClassName: "text-primary", label: "Reply" };
|
|
15774
15792
|
case "document_activity":
|
|
@@ -16201,6 +16219,27 @@ function describeServerNotification(n, options = {}) {
|
|
|
16201
16219
|
target: { kind: "support", ticketId }
|
|
16202
16220
|
};
|
|
16203
16221
|
}
|
|
16222
|
+
// A request waiting for this approver's decision, or a decision on the recipient's request: ids only
|
|
16223
|
+
// (`{database_id, row_id, column_id}`); the row opens in its database.
|
|
16224
|
+
case "database_row_submitted":
|
|
16225
|
+
case "database_row_decided": {
|
|
16226
|
+
const meta = parse(n.content);
|
|
16227
|
+
const databaseId = meta?.database_id;
|
|
16228
|
+
const rowId = meta?.row_id;
|
|
16229
|
+
if (typeof databaseId !== "string" || !/^dbs-[a-zA-Z0-9]{8}$/.test(databaseId)) return null;
|
|
16230
|
+
const submitted = type === "database_row_submitted";
|
|
16231
|
+
return {
|
|
16232
|
+
title: submitted ? `${senderName} submitted a request for your decision` : `${senderName} decided your request`,
|
|
16233
|
+
variant: "info",
|
|
16234
|
+
actionLabel: submitted ? "Review" : "Open",
|
|
16235
|
+
target: {
|
|
16236
|
+
kind: "database",
|
|
16237
|
+
databaseId,
|
|
16238
|
+
...typeof rowId === "string" && /^dbr-[a-zA-Z0-9]{8}$/.test(rowId) ? { rowId } : {},
|
|
16239
|
+
...n.workspace_ext_id ? { workspaceId: n.workspace_ext_id } : {}
|
|
16240
|
+
}
|
|
16241
|
+
};
|
|
16242
|
+
}
|
|
16204
16243
|
case "file_shared": {
|
|
16205
16244
|
const meta = parse(n.content);
|
|
16206
16245
|
const id = meta?.file_share_id;
|
|
@@ -20102,6 +20141,7 @@ exports.ChatBubble = ChatBubble;
|
|
|
20102
20141
|
exports.CitationRenderer = CitationRenderer;
|
|
20103
20142
|
exports.ConversationList = ConversationList;
|
|
20104
20143
|
exports.ConversationScope = ConversationScope;
|
|
20144
|
+
exports.DATABASES_OPEN_VIEW = DATABASES_OPEN_VIEW;
|
|
20105
20145
|
exports.DATABASE_RELATION_PICK_LIMIT = DATABASE_RELATION_PICK_LIMIT;
|
|
20106
20146
|
exports.DATABASE_ROWS_PAGE = DATABASE_ROWS_PAGE;
|
|
20107
20147
|
exports.DEFAULT_ACTIVITY_SOURCE_LABELS = DEFAULT_ACTIVITY_SOURCE_LABELS;
|
|
@@ -20664,6 +20704,7 @@ exports.useSetSkillVisibility = useSetSkillVisibility;
|
|
|
20664
20704
|
exports.useSetWorkspaceHouseTemplate = useSetWorkspaceHouseTemplate;
|
|
20665
20705
|
exports.useSetWorkspaceMemberRoles = useSetWorkspaceMemberRoles;
|
|
20666
20706
|
exports.useShareCalendar = useShareCalendar;
|
|
20707
|
+
exports.useShareDatabaseRow = useShareDatabaseRow;
|
|
20667
20708
|
exports.useShellWorkspaces = useShellWorkspaces;
|
|
20668
20709
|
exports.useSignOut = useSignOut;
|
|
20669
20710
|
exports.useSkillSource = useSkillSource;
|