π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: table and view entries
mertmit6e204374007c
diff --git a/packages/nc-gui/composables/useInfiniteData.ts b/packages/nc-gui/composables/useInfiniteData.tsindex 4b31cd2f7f..eeb85f20e6 100644--- a/packages/nc-gui/composables/useInfiniteData.ts+++ b/packages/nc-gui/composables/useInfiniteData.ts@@ -3,6 +3,7 @@ import {type Api,type ColumnType,type DataPayload,+ EventType,type FilterType,type LinkToAnotherRecordType,NcApiVersion,@@ -2026,15 +2027,23 @@ export function useInfiniteData(args: {}})+ const activeChannel = ref<string | null>(null)+watch(meta,(newMeta, oldMeta) => {if (newMeta?.fk_workspace_id && newMeta?.base_id && newMeta?.id) {if (oldMeta?.id && oldMeta.id === newMeta.id) return- $ncSocket.subscribe(`event-data:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`)+ if (activeChannel.value) {+ $ncSocket.offMessage(activeChannel.value)+ }++ activeChannel.value = `${EventType.DATA_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`++ $ncSocket.subscribe(activeChannel.value)- $ncSocket.onMessage(`event-data:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`, (data: DataPayload) => {+ $ncSocket.onMessage(activeChannel.value, (data: DataPayload) => {const { id, action, payload, before } = dataif (action === 'add') {diff --git a/packages/nc-gui/composables/useRealtime.ts b/packages/nc-gui/composables/useRealtime.tsnew file mode 100644index 0000000000..9b010fb24c--- /dev/null+++ b/packages/nc-gui/composables/useRealtime.ts@@ -0,0 +1,3 @@+export const useRealtime = createSharedComposable(() => {+ return {}+})diff --git a/packages/nc-gui/composables/useSmartsheetStore.ts b/packages/nc-gui/composables/useSmartsheetStore.tsindex e5a9f9161a..1a84ce753d 100644--- a/packages/nc-gui/composables/useSmartsheetStore.ts+++ b/packages/nc-gui/composables/useSmartsheetStore.ts@@ -1,7 +1,6 @@import type { ColumnType, FilterType, KanbanType, SortType, TableType, ViewType } from 'nocodb-sdk'import { NcApiVersion, ViewLockType, ViewTypes, extractFilterFromXwhere } from 'nocodb-sdk'import type { Ref } from 'vue'-import { EventBusEnum, type SmartsheetStoreEvents } from '#imports'const [useProvideSmartsheetStore, useSmartsheetStore] = useInjectionState((@@ -14,7 +13,7 @@ const [useProvideSmartsheetStore, useSmartsheetStore] = useInjectionState() => {const isPublic = inject(IsPublicInj, ref(false))- const { $api } = useNuxtApp()+ const { $api, $eventBus } = useNuxtApp()const router = useRouter()const route = router.currentRoute@@ -33,7 +32,7 @@ const [useProvideSmartsheetStore, useSmartsheetStore] = useInjectionState(const { search, getValidSearchQueryForColumn } = useFieldQuery()- const eventBus = useEventBus<SmartsheetStoreEvents>(EventBusEnum.SmartsheetStore)+ const eventBus = $eventBus.smartsheetStoreEventBusconst isLocked = computed(() =>diff --git a/packages/nc-gui/nuxt-shim.d.ts b/packages/nc-gui/nuxt-shim.d.tsindex d04aebb800..ac288ea034 100644--- a/packages/nc-gui/nuxt-shim.d.ts+++ b/packages/nc-gui/nuxt-shim.d.ts@@ -1,4 +1,5 @@import type { Api as BaseAPI } from 'nocodb-sdk'+import type { UseEventBusReturn } from '@vueuse/core'import type { UseGlobalReturn } from './composables/useGlobal/types'import type { NocoI18n } from './lib'import type { TabType } from './composables'@@ -39,6 +40,9 @@ declare module '#app' {onMessage: (evt: string, handler: (...args: any[]) => void) => voidoffMessage: (evt: string) => void}+ $eventBus: {+ smartsheetStoreEventBus: UseEventBusReturn<string, any>+ }}}diff --git a/packages/nc-gui/plugins/event-bus.ts b/packages/nc-gui/plugins/event-bus.tsnew file mode 100644index 0000000000..7282529fc4--- /dev/null+++ b/packages/nc-gui/plugins/event-bus.ts@@ -0,0 +1,6 @@+export default defineNuxtPlugin(function (nuxtApp) {+ const smartsheetStoreEventBus = useEventBus<SmartsheetStoreEvents>(EventBusEnum.SmartsheetStore)+ nuxtApp.provide('eventBus', {+ smartsheetStoreEventBus,+ })+})diff --git a/packages/nc-gui/store/tables.ts b/packages/nc-gui/store/tables.tsindex 731581bcfe..754e1acf61 100644--- a/packages/nc-gui/store/tables.ts+++ b/packages/nc-gui/store/tables.ts@@ -1,12 +1,12 @@import { acceptHMRUpdate, defineStore } from 'pinia'-import type { TableType } from 'nocodb-sdk'+import { EventType, type TableType } from 'nocodb-sdk'import type { SidebarTableNode } from '~/lib/types'import { DlgTableCreate } from '#components'export const useTablesStore = defineStore('tablesStore', () => {const { includeM2M, ncNavigateTo } = useGlobal()const { api } = useApi()- const { $e, $api } = useNuxtApp()+ const { $e, $api, $ncSocket } = useNuxtApp()const { addUndo, defineProjectScope } = useUndoRedo()const { refreshCommandPalette } = useCommandPalette()@@ -301,6 +301,69 @@ export const useTablesStore = defineStore('tablesStore', () => {}}+ const activeChannel = ref<string | null>(null)++ watch(+ () => basesStore.activeProjectId,+ async (baseId) => {+ if (!baseId) return++ if (activeChannel.value) {+ $ncSocket.offMessage(activeChannel.value)+ }++ activeChannel.value = `${EventType.META_EVENT}:${workspaceStore.activeWorkspaceId}:${baseId}`++ $ncSocket.subscribe(activeChannel.value)++ $ncSocket.onMessage(activeChannel.value, (event) => {+ if (event.action === 'table_create') {+ const tables = baseTables.value.get(baseId)+ if (!tables) {+ loadProjectTables(baseId, true)+ } else {+ tables.push(event.payload)+ baseTables.value.set(baseId, tables)+ }+ } else if (event.action === 'table_update') {+ const updatedTable = event.payload+ const tables = baseTables.value.get(baseId)+ if (tables) {+ const index = tables.findIndex((t) => t.id === updatedTable.id)+ if (index !== -1) {+ tables[index] = updatedTable+ }+ baseTables.value.set(baseId, tables)+ } else {+ loadProjectTables(baseId, true)+ }+ } else if (event.action === 'table_delete') {+ const deletedTableId = event.payload.id+ const tables = baseTables.value.get(baseId)+ if (tables) {+ const updatedTables = tables.filter((t) => t.id !== deletedTableId)+ baseTables.value.set(baseId, updatedTables)++ if (activeTableId.value === deletedTableId && updatedTables.length > 0 && updatedTables[0]?.id) {+ navigateToTable({+ tableId: updatedTables[0].id,+ })+ } else {+ ncNavigateTo({+ workspaceId: workspaceStore.activeWorkspaceId,+ baseId,+ tableId: undefined,+ })+ }+ } else {+ loadProjectTables(baseId, true)+ }+ }+ })+ },+ { immediate: true },+ )+return {baseTables,loadProjectTables,diff --git a/packages/nocodb-sdk/src/lib/realtime/index.ts b/packages/nocodb-sdk/src/lib/realtime/index.tsindex ee016797f3..9657059a2c 100644--- a/packages/nocodb-sdk/src/lib/realtime/index.ts+++ b/packages/nocodb-sdk/src/lib/realtime/index.ts@@ -1,4 +1,4 @@-import { ScriptType, UserType } from '~/lib/Api';+import { ScriptType, TableType, UserType, ViewType } from '~/lib/Api';import { DashboardType, WidgetType } from '~/lib';export enum EventType {@@ -45,6 +45,11 @@ export interface DataPayload extends BaseSocketPayload {before?: string;}+export interface MetaPayload extends BaseSocketPayload {+ action: 'table_create' | 'table_update' | 'table_delete' | 'column_add' | 'column_update' | 'column_delete' | 'view_create' | 'view_update' | 'view_delete';+ payload: Partial<TableType | ViewType>;+}+export interface DashboardPayload extends BaseSocketPayload {id: string;action: 'create' | 'update' | 'delete';@@ -69,6 +74,7 @@ export type SocketEventPayload =| ConnectionWelcomePayload| ConnectionErrorPayload| DataPayload+ | MetaPayload| DashboardPayload| WidgetPayload;@@ -77,6 +83,7 @@ export type SocketEventPayloadMap = {[EventType.CONNECTION_WELCOME]: ConnectionWelcomePayload;[EventType.CONNECTION_ERROR]: ConnectionErrorPayload;[EventType.DATA_EVENT]: DataPayload;+ [EventType.META_EVENT]: MetaPayload;[EventType.DASHBOARD_EVENT]: DashboardPayload;[EventType.WIDGET_EVENT]: WidgetPayload;[EventType.SCRIPT_EVENT]: ScriptPayload;diff --git a/packages/nocodb/src/services/calendars.service.ts b/packages/nocodb/src/services/calendars.service.tsindex dc6984dcec..9c3258d00e 100644--- a/packages/nocodb/src/services/calendars.service.ts+++ b/packages/nocodb/src/services/calendars.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common';-import { AppEvents, ViewTypes } from 'nocodb-sdk';+import { AppEvents, EventType, ViewTypes } from 'nocodb-sdk';import type {CalendarUpdateReqType,UserType,@@ -12,6 +12,7 @@ import { NcError } from '~/helpers/catchError';import { CalendarView, Model, User, View } from '~/models';import NocoCache from '~/cache/NocoCache';import { CacheScope } from '~/utils/globals';+import NocoSocket from '~/socket/NocoSocket';@Injectable()export class CalendarsService {@@ -76,6 +77,18 @@ export class CalendarsService {owner,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'view_create',+ payload: view,+ },+ },+ context.socket_id,+ );+return view;}diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.tsindex 73c96d270e..136cbae0db 100644--- a/packages/nocodb/src/services/columns.service.ts+++ b/packages/nocodb/src/services/columns.service.ts@@ -3,6 +3,7 @@ import { pluralize, singularize } from 'inflection';import {AppEvents,ButtonActionsType,+ EventType,FormulaDataTypes,isAIPromptCol,isCreatedOrLastModifiedByCol,@@ -88,6 +89,7 @@ import {} from '~/utils/dataConversion';import { MetaTable } from '~/utils/globals';import { parseMetaProp } from '~/utils/modelUtils';+import NocoSocket from '~/socket/NocoSocket';export type { ReusableParams } from '~/services/columns.service.type';@@ -1864,6 +1866,18 @@ export class ColumnsService implements IColumnsService {columns: table.columns,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'column_update',+ payload: table,+ },+ },+ context.socket_id,+ );+await applyRowColorInvolvement();if (param.apiVersion === NcApiVersion.V3) {@@ -2616,6 +2630,18 @@ export class ColumnsService implements IColumnsService {});}+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'column_add',+ payload: table,+ },+ },+ context.socket_id,+ );+if (param.apiVersion === NcApiVersion.V3) {if (savedColumn)return (await Column.get(context, {@@ -3187,6 +3213,18 @@ export class ColumnsService implements IColumnsService {});}+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'column_delete',+ payload: table,+ },+ },+ context.socket_id,+ );+await applyRowColorInvolvement();return table;diff --git a/packages/nocodb/src/services/forms.service.ts b/packages/nocodb/src/services/forms.service.tsindex 2cebdef2e8..a2755f3853 100644--- a/packages/nocodb/src/services/forms.service.ts+++ b/packages/nocodb/src/services/forms.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common';-import { AppEvents, ViewTypes } from 'nocodb-sdk';+import { AppEvents, EventType, ViewTypes } from 'nocodb-sdk';import type {FormUpdateReqType,UserType,@@ -12,6 +12,7 @@ import { NcError } from '~/helpers/catchError';import { FormView, Model, Source, User, View } from '~/models';import NocoCache from '~/cache/NocoCache';import { CacheScope } from '~/utils/globals';+import NocoSocket from '~/socket/NocoSocket';@Injectable()export class FormsService {@@ -89,6 +90,18 @@ export class FormsService {context,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'view_create',+ payload: view,+ },+ },+ context.socket_id,+ );+return view;}diff --git a/packages/nocodb/src/services/galleries.service.ts b/packages/nocodb/src/services/galleries.service.tsindex 46959278ba..d9e865a2e2 100644--- a/packages/nocodb/src/services/galleries.service.ts+++ b/packages/nocodb/src/services/galleries.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common';-import { AppEvents, ViewTypes } from 'nocodb-sdk';+import { AppEvents, EventType, ViewTypes } from 'nocodb-sdk';import type {GalleryUpdateReqType,UserType,@@ -12,6 +12,7 @@ import { NcError } from '~/helpers/catchError';import { GalleryView, Model, User, View } from '~/models';import NocoCache from '~/cache/NocoCache';import { CacheScope } from '~/utils/globals';+import NocoSocket from '~/socket/NocoSocket';@Injectable()export class GalleriesService {@@ -76,6 +77,19 @@ export class GalleriesService {owner,context,});++ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'view_create',+ payload: view,+ },+ },+ context.socket_id,+ );+return view;}diff --git a/packages/nocodb/src/services/grids.service.ts b/packages/nocodb/src/services/grids.service.tsindex 3084118804..1d2b648bc0 100644--- a/packages/nocodb/src/services/grids.service.ts+++ b/packages/nocodb/src/services/grids.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common';-import { AppEvents, ViewTypes } from 'nocodb-sdk';+import { AppEvents, EventType, ViewTypes } from 'nocodb-sdk';import type { GridUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';@@ -8,6 +8,7 @@ import { NcError } from '~/helpers/catchError';import { GridView, Model, User, View } from '~/models';import NocoCache from '~/cache/NocoCache';import { CacheScope } from '~/utils/globals';+import NocoSocket from '~/socket/NocoSocket';@Injectable()export class GridsService {@@ -64,6 +65,18 @@ export class GridsService {context,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'view_create',+ payload: view,+ },+ },+ context.socket_id,+ );+return view;}diff --git a/packages/nocodb/src/services/kanbans.service.ts b/packages/nocodb/src/services/kanbans.service.tsindex af6af47215..3b376b82b4 100644--- a/packages/nocodb/src/services/kanbans.service.ts+++ b/packages/nocodb/src/services/kanbans.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common';-import { AppEvents, UITypes, ViewTypes } from 'nocodb-sdk';+import { AppEvents, EventType, UITypes, ViewTypes } from 'nocodb-sdk';import type {KanbanUpdateReqType,UserType,@@ -12,6 +12,7 @@ import { NcError } from '~/helpers/catchError';import { KanbanView, Model, User, View } from '~/models';import NocoCache from '~/cache/NocoCache';import { CacheScope } from '~/utils/globals';+import NocoSocket from '~/socket/NocoSocket';@Injectable()export class KanbansService {@@ -96,6 +97,18 @@ export class KanbansService {context,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'view_create',+ payload: view,+ },+ },+ context.socket_id,+ );+return view;}diff --git a/packages/nocodb/src/services/tables.service.ts b/packages/nocodb/src/services/tables.service.tsindex e43521a1ee..735a50dd49 100644--- a/packages/nocodb/src/services/tables.service.ts+++ b/packages/nocodb/src/services/tables.service.ts@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';import DOMPurify from 'isomorphic-dompurify';import {AppEvents,+ EventType,isCreatedOrLastModifiedByCol,isCreatedOrLastModifiedTimeCol,isLinksOrLTAR,@@ -41,6 +42,7 @@ import {getUniqueColumnName,} from '~/helpers/getUniqueName';import { MetaTable } from '~/utils/globals';+import NocoSocket from '~/socket/NocoSocket';@Injectable()export class TablesService {@@ -196,6 +198,8 @@ export class TablesService {param.table.table_name,);+ const result = await Model.get(context, param.tableId);+this.appHooksService.emit(AppEvents.TABLE_UPDATE, {table: param.table,prevTable: model,@@ -203,6 +207,18 @@ export class TablesService {context,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'table_update',+ payload: result,+ },+ },+ context.socket_id,+ );+return true;}@@ -374,6 +390,14 @@ export class TablesService {});}+ result = await table.delete(context, ncMeta);+ await ncMeta.commit();+ } catch (e) {+ await ncMeta.rollback();+ throw e;+ }++ if (result) {this.appHooksService.emit(AppEvents.TABLE_DELETE, {table,user: param.user,@@ -381,12 +405,19 @@ export class TablesService {context,});- result = await table.delete(context, ncMeta);- await ncMeta.commit();- } catch (e) {- await ncMeta.rollback();- throw e;+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'table_delete',+ payload: table,+ },+ },+ context.socket_id,+ );}+return result;}@@ -950,6 +981,18 @@ export class TablesService {context,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'table_create',+ payload: result,+ },+ },+ context.socket_id,+ );+return result;}}diff --git a/packages/nocodb/src/services/views.service.ts b/packages/nocodb/src/services/views.service.tsindex 3ce99ef8da..d0db5b241f 100644--- a/packages/nocodb/src/services/views.service.ts+++ b/packages/nocodb/src/services/views.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common';-import { AppEvents, ProjectRoles, ViewTypes } from 'nocodb-sdk';+import { AppEvents, EventType, ProjectRoles, ViewTypes } from 'nocodb-sdk';import type {SharedViewReqType,UserType,@@ -17,6 +17,7 @@ import {User,View,} from '~/models';+import NocoSocket from '~/socket/NocoSocket';// todo: moveasync function xcVisibilityMetaGet(@@ -244,6 +245,19 @@ export class ViewsService {context,owner,});++ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'view_update',+ payload: result,+ },+ },+ context.socket_id,+ );+return result;}@@ -288,6 +302,18 @@ export class ViewsService {context,});+ NocoSocket.broadcastEvent(+ context,+ {+ event: EventType.META_EVENT,+ payload: {+ action: 'view_delete',+ payload: view,+ },+ },+ context.socket_id,+ );+return true;}