π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: api for baseListAll
mertmit2e812778d7d7
diff --git a/packages/nocodb/src/controllers/internal/modules/BaseListAllGet.operations.ts b/packages/nocodb/src/controllers/internal/modules/BaseListAllGet.operations.tsnew file mode 100644index 0000000000..1f877c1258--- /dev/null+++ b/packages/nocodb/src/controllers/internal/modules/BaseListAllGet.operations.ts@@ -0,0 +1,31 @@+import { Injectable } from '@nestjs/common';+import type { OPERATION_SCOPES } from '~/controllers/internal/operationScopes';+import type { NcContext, NcRequest } from 'nocodb-sdk';+import type {+ InternalApiModule,+ InternalGETResponseType,+} from '~/utils/internal-type';+import { getBaseListAll } from '~/helpers/baseListAllHelpers';++@Injectable()+export class BaseListAllGetOperations+ implements InternalApiModule<InternalGETResponseType>+{+ operations = ['baseListAll' as const];+ httpMethod = 'GET' as const;++ async handle(+ _context: NcContext,+ {+ req,+ }: {+ workspaceId: string;+ baseId: string;+ operation: keyof typeof OPERATION_SCOPES;+ payload: any;+ req: NcRequest;+ },+ ): InternalGETResponseType {+ return await getBaseListAll(req.user.id);+ }+}diff --git a/packages/nocodb/src/controllers/internal/operationScopes.ts b/packages/nocodb/src/controllers/internal/operationScopes.tsindex 17fe62803c..270d6da972 100644--- a/packages/nocodb/src/controllers/internal/operationScopes.ts+++ b/packages/nocodb/src/controllers/internal/operationScopes.ts@@ -5,6 +5,7 @@ export const OPERATION_SCOPES = {mcpDelete: 'base',mcpGet: 'base',mcpRootList: 'org',+ baseListAll: 'org',recordAuditList: 'base',oAuthClientList: 'org',oAuthClientCreate: 'org',diff --git a/packages/nocodb/src/controllers/internal/provider.ts b/packages/nocodb/src/controllers/internal/provider.tsindex c0febd2902..642751df17 100644--- a/packages/nocodb/src/controllers/internal/provider.ts+++ b/packages/nocodb/src/controllers/internal/provider.ts@@ -7,6 +7,7 @@ import { OAuthPostOperations } from '~/controllers/internal/modules/OAuthPost.opimport { DependencyPostOperations } from '~/controllers/internal/modules/DependencyPost.operations';import { UiGetOperations } from '~/controllers/internal/modules/UiGet.operations';import { UiPostOperations } from '~/controllers/internal/modules/UiPost.operations';+import { BaseListAllGetOperations } from '~/controllers/internal/modules/BaseListAllGet.operations';import { INTERNAL_API_MODULE_PROVIDER_KEY } from '~/utils/internal-type';export const InternalApiModules = [@@ -18,6 +19,7 @@ export const InternalApiModules = [DependencyPostOperations,UiGetOperations,UiPostOperations,+ BaseListAllGetOperations,];export const InternalApiModuleProvider = {diff --git a/packages/nocodb/src/helpers/baseListAllHelpers.ts b/packages/nocodb/src/helpers/baseListAllHelpers.tsnew file mode 100644index 0000000000..ca466a1503--- /dev/null+++ b/packages/nocodb/src/helpers/baseListAllHelpers.ts@@ -0,0 +1,78 @@+import { ProjectRoles } from 'nocodb-sdk';+import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';+import Noco from '~/Noco';+import NocoCache from '~/cache/NocoCache';+import { parseMetaProp } from '~/utils/modelUtils';++export interface BaseListAllResult {+ workspaces: {+ id: string;+ title: string;+ meta: Record<string, any>;+ bases: {+ id: string;+ title: string;+ meta: Record<string, any>;+ role: string;+ order: number;+ managed_app_master?: boolean;+ managed_app_id?: string | null;+ }[];+ }[];+}++export async function getBaseListAll(+ userId: string,+ ncMeta = Noco.ncMeta,+): Promise<BaseListAllResult> {+ const key = `${CacheScope.CMD_PALETTE}:baseListAll:${userId}`;++ let cached = await NocoCache.get('root', key, CacheGetType.TYPE_OBJECT);++ if (!cached) {+ const rows = await ncMeta+ .knexConnection(`${MetaTable.PROJECT} as b`)+ .select(+ 'b.id as base_id',+ 'b.title as base_title',+ 'b.meta as base_meta',+ 'bu.roles as base_role',+ 'b.order as base_order',+ )+ .innerJoin(`${MetaTable.PROJECT_USERS} as bu`, `b.id`, `bu.base_id`)+ .where('bu.fk_user_id', userId)+ .andWhereNot('bu.roles', ProjectRoles.NO_ACCESS)+ .andWhere(function () {+ this.where('b.deleted', false).orWhereNull('b.deleted');+ })+ .orderBy('b.order', 'asc');++ const bases = rows.map((row) => ({+ id: row.base_id,+ title: row.base_title,+ meta: parseMetaProp(row, 'base_meta'),+ role: row.base_role,+ order: row.base_order ?? 0,+ }));++ cached = {+ workspaces: [+ {+ id: 'nc',+ title: 'NocoDB',+ meta: {},+ bases,+ },+ ],+ };++ await NocoCache.set('root', key, cached);+ // Append to the same lists command palette uses so cleanup piggybacks+ await NocoCache.set('root', `${CacheScope.CMD_PALETTE}:ws`, [key]);+ await NocoCache.set('root', `${CacheScope.CMD_PALETTE}:user:${userId}`, [+ key,+ ]);+ }++ return cached;+}diff --git a/packages/nocodb/src/utils/acl.ts b/packages/nocodb/src/utils/acl.tsindex 737fb98f77..2534b7bb32 100644--- a/packages/nocodb/src/utils/acl.ts+++ b/packages/nocodb/src/utils/acl.ts@@ -46,6 +46,7 @@ const permissionScopes = {// Misc'commandPalette',+ 'baseListAll','testConnection','genericGPT','duplicateSharedBase',@@ -384,6 +385,7 @@ const rolePermissions:testConnection: true,isPluginActive: true,commandPalette: true,+ baseListAll: true,notification: true,// oAuth@@ -646,6 +648,7 @@ const permissionDescriptions: Record<string, string> = {pluginUpdate: 'update plugin configuration',commandPalette: 'access the command palette',+ baseListAll: 'list all workspaces and bases',testConnection: 'test connection to a service',genericGPT: 'use generic GPT functionality',diff --git a/packages/nocodb/src/utils/internal-type.ts b/packages/nocodb/src/utils/internal-type.tsindex 94baaa6195..2e4430704e 100644--- a/packages/nocodb/src/utils/internal-type.ts+++ b/packages/nocodb/src/utils/internal-type.ts@@ -37,6 +37,7 @@ export type InternalGETResponseType = Promise<| OAuthClient[]| Extension| Extension[]+ | { workspaces: any[] }>;export type InternalPOSTResponseType = Promise<