Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
import type { DatabaseEntity } from '@entity';
import type { ListedDatabase } from '@service-storage/generated/schemas/listedDatabase';
import type { DriveSelection } from '../context/drive-source';
/**
* Databases have no view history; list them in file tabs and in the folder
* they are filed in. `hidden` names databases made for a form kept out of
* Drive, like a poll's.
*/
export function selectDriveDatabases(
listed: readonly ListedDatabase[],
selection: DriveSelection,
userId: string | undefined,
hidden: ReadonlySet<string>
): DatabaseEntity[] {
const { location, scope } = selection;
if (!userId || scope === 'attachments') return [];
if (location.kind === 'tab' && location.tab === 'recent') return [];
if (location.kind === 'folder' && !location.id) return [];
const search = selection.search.trim().toLocaleLowerCase();
return listed.flatMap(({ database, grant }) => {
if (database.trashed_at || hidden.has(database.id)) return [];
if (location.kind === 'folder' && database.project_id !== location.id)
return [];
if (
location.kind === 'tab' &&
location.tab === 'shared' &&
database.owner_id === userId
)
return [];
if (
location.kind === 'tab' &&
location.tab === 'owned' &&
scope === 'default' &&
database.owner_id !== userId
)
return [];
if (search && !database.name.toLocaleLowerCase().includes(search))
return [];
return [
{
type: 'database',
id: database.id,
name: database.name,
ownerId: database.owner_id,
createdAt: database.created_at,
grant,
projectId: database.project_id ?? undefined,
},
];
});
}
/** Every database the viewer can open, owned or shared, for the sidebar, alphabetical. */
export function selectSidebarDatabases(
listed: readonly ListedDatabase[],
hidden: ReadonlySet<string>
): DatabaseEntity[] {
return listed
.flatMap(({ database, grant }): DatabaseEntity[] =>
database.trashed_at || hidden.has(database.id)
? []
: [
{
type: 'database',
id: database.id,
name: database.name,
ownerId: database.owner_id,
createdAt: database.created_at,
grant,
projectId: database.project_id ?? undefined,
},
]
)
.sort((a, b) => a.name.localeCompare(b.name));
}