π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
put webHookManager on most of view update operations
Fendy Heryantoa6fbda73e840
diff --git a/packages/nocodb/src/models/Filter.ts b/packages/nocodb/src/models/Filter.tsindex 452d4e30d1..fcfc19a817 100644--- a/packages/nocodb/src/models/Filter.ts+++ b/packages/nocodb/src/models/Filter.ts@@ -605,6 +605,7 @@ export default class Filter implements FilterType {return result;}+ // skip viewWebhookManager for this, deleteAll is not a standalone operation, it's invoked by view servicestatic async deleteAll(context: NcContext,viewId: string,diff --git a/packages/nocodb/src/models/Sort.ts b/packages/nocodb/src/models/Sort.tsindex cffb21c439..40511a3520 100644--- a/packages/nocodb/src/models/Sort.ts+++ b/packages/nocodb/src/models/Sort.ts@@ -27,6 +27,7 @@ export default class Sort {Object.assign(this, data);}+ // skip viewWebhookManager for this, Sort.deleteAll is not a standalone operation, it's invoked by view servicepublic static async deleteAll(context: NcContext,viewId: string,diff --git a/packages/nocodb/src/services/calendars.service.ts b/packages/nocodb/src/services/calendars.service.tsindex 6a2c82b690..5e72394474 100644--- a/packages/nocodb/src/services/calendars.service.ts+++ b/packages/nocodb/src/services/calendars.service.ts@@ -1,6 +1,5 @@import { Injectable } from '@nestjs/common';import { AppEvents, EventType, ViewTypes } from 'nocodb-sdk';-import type { ViewWebhookManager } from '~/utils/view-webhook-manager';import type {CalendarUpdateReqType,UserType,@@ -8,6 +7,10 @@ import type {} from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';import { NcError } from '~/helpers/catchError';@@ -43,6 +46,14 @@ export class CalendarsService {const model = await Model.get(context, param.tableId, ncMeta);+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ param.tableId,+ )+ ).forCreate();+const { id } = await View.insertMetaOnly(context,{@@ -99,6 +110,10 @@ export class CalendarsService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }+return view;}@@ -108,6 +123,7 @@ export class CalendarsService {calendarViewId: string;calendar: CalendarUpdateReqType;req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},ncMeta?: MetaService,) {@@ -122,6 +138,16 @@ export class CalendarsService {NcError.viewNotFound(param.calendarViewId);}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(view.id)+ ).forUpdate();+const oldCalendarView = await CalendarView.get(context,param.calendarViewId,@@ -167,6 +193,9 @@ export class CalendarsService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }return view;}}diff --git a/packages/nocodb/src/services/forms.service.ts b/packages/nocodb/src/services/forms.service.tsindex c2036239e0..990a561896 100644--- a/packages/nocodb/src/services/forms.service.ts+++ b/packages/nocodb/src/services/forms.service.ts@@ -7,7 +7,10 @@ import type {} from 'nocodb-sdk';import type { MetaService } from '~/meta/meta.service';import type { NcContext, NcRequest } from '~/interface/config';-import type { ViewWebhookManager } from '~/utils/view-webhook-manager';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';import { NcError } from '~/helpers/catchError';@@ -56,6 +59,13 @@ export class FormsService {NcError.sourceDataReadOnly(source.alias);}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ param.tableId,+ )+ ).forCreate();const { id } = await View.insertMetaOnly(context,{@@ -111,6 +121,10 @@ export class FormsService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }+return view;}@@ -120,6 +134,7 @@ export class FormsService {formViewId: string;form: FormUpdateReqType;req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},ncMeta?: MetaService,) {@@ -133,6 +148,16 @@ export class FormsService {NcError.viewNotFound(param.formViewId);}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(view.id)+ ).forUpdate();+const oldFormView = await FormView.get(context, param.formViewId, ncMeta);await FormView.update(context, param.formViewId, param.form, ncMeta);@@ -166,6 +191,9 @@ export class FormsService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }return view;}}diff --git a/packages/nocodb/src/services/galleries.service.ts b/packages/nocodb/src/services/galleries.service.tsindex 538fc39408..235db7e56d 100644--- a/packages/nocodb/src/services/galleries.service.ts+++ b/packages/nocodb/src/services/galleries.service.ts@@ -7,7 +7,10 @@ import type {} from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';-import type { ViewWebhookManager } from '~/utils/view-webhook-manager';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';import { NcError } from '~/helpers/catchError';@@ -43,6 +46,13 @@ export class GalleriesService {const model = await Model.get(context, param.tableId, ncMeta);+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ param.tableId,+ )+ ).forCreate();const { id } = await View.insertMetaOnly(context,{@@ -100,6 +110,10 @@ export class GalleriesService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }+return view;}@@ -109,6 +123,7 @@ export class GalleriesService {galleryViewId: string;gallery: GalleryUpdateReqType;req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},ncMeta?: MetaService,) {@@ -123,6 +138,16 @@ export class GalleriesService {NcError.viewNotFound(param.galleryViewId);}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(view.id)+ ).forUpdate();+const oldGalleryView = await GalleryView.get(context,param.galleryViewId,@@ -165,6 +190,9 @@ export class GalleriesService {},context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }return view;}}diff --git a/packages/nocodb/src/services/grid-columns.service.ts b/packages/nocodb/src/services/grid-columns.service.tsindex 147daaaa49..dd79ebfad3 100644--- a/packages/nocodb/src/services/grid-columns.service.ts+++ b/packages/nocodb/src/services/grid-columns.service.ts@@ -3,6 +3,10 @@ import { AppEvents, EventType } from 'nocodb-sdk';import type { GridColumnReqType } from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { MetaTable } from '~/cli';import NocoCache from '~/cache/NocoCache';import { CacheDelDirection, CacheScope } from '~/utils/globals';@@ -31,6 +35,7 @@ export class GridColumnsService {gridViewColumnId: string;grid: GridColumnReqType;req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},ncMeta?: MetaService,) {@@ -54,6 +59,17 @@ export class GridColumnsService {);const view = await View.get(context, oldGridViewColumn.fk_view_id, ncMeta);++ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(view.id)+ ).forUpdate();+const res = await GridViewColumn.update(context,param.gridViewColumnId,@@ -95,6 +111,9 @@ export class GridColumnsService {},context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }return res;}diff --git a/packages/nocodb/src/services/grids.service.ts b/packages/nocodb/src/services/grids.service.tsindex 51b14b2259..47707d7a24 100644--- a/packages/nocodb/src/services/grids.service.ts+++ b/packages/nocodb/src/services/grids.service.ts@@ -3,7 +3,10 @@ import { AppEvents, EventType, ViewTypes } from 'nocodb-sdk';import type { GridUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';-import type { ViewWebhookManager } from '~/utils/view-webhook-manager';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';import { NcError } from '~/helpers/catchError';@@ -32,6 +35,14 @@ export class GridsService {param.grid,);+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ param.tableId,+ )+ ).forCreate();+const model = await Model.get(context, param.tableId, ncMeta);const { id } = await View.insertMetaOnly(@@ -87,6 +98,10 @@ export class GridsService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }+return view;}@@ -96,6 +111,7 @@ export class GridsService {viewId: string;grid: GridUpdateReqType;req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},ncMeta?: MetaService,) {@@ -111,6 +127,16 @@ export class GridsService {}const oldGridView = await GridView.get(context, param.viewId, ncMeta);+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(param.viewId)+ ).forUpdate();+await GridView.update(context, param.viewId, param.grid, ncMeta);let owner = param.req.user;@@ -141,6 +167,10 @@ export class GridsService {},context.socket_id,);++ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }return view;}}diff --git a/packages/nocodb/src/services/kanbans.service.ts b/packages/nocodb/src/services/kanbans.service.tsindex d48722a1ff..4b7b0157f8 100644--- a/packages/nocodb/src/services/kanbans.service.ts+++ b/packages/nocodb/src/services/kanbans.service.ts@@ -14,7 +14,10 @@ import type {import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';import type { SelectOption } from '~/models';-import type { ViewWebhookManager } from '~/utils/view-webhook-manager';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';import { NcError } from '~/helpers/catchError';@@ -72,6 +75,14 @@ export class KanbansService {}}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ param.tableId,+ )+ ).forCreate();+const { id } = await View.insertMetaOnly(context,{@@ -132,6 +143,10 @@ export class KanbansService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }+return view;}@@ -141,6 +156,7 @@ export class KanbansService {kanbanViewId: string;kanban: KanbanUpdateReqType;req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},ncMeta?: MetaService,) {@@ -155,6 +171,16 @@ export class KanbansService {NcError.viewNotFound(param.kanbanViewId);}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(view.id)+ ).forUpdate();+const oldKanbanView = await KanbanView.get(context,param.kanbanViewId,@@ -210,6 +236,9 @@ export class KanbansService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }return view;}@@ -318,11 +347,23 @@ export class KanbansService {kanbanViewId: string;optionsOrder: string[];req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},ncMeta?: MetaService,) {const kanbanView = await this.kanbanViewGet(context, param, ncMeta);const modelView = await View.get(context, kanbanView.fk_view_id, ncMeta);++ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ modelView.fk_model_id,+ )+ ).withViewId(modelView.id)+ ).forUpdate();+const model = await Model.get(context, modelView.fk_model_id, ncMeta);const column = (await model.getColumns(context, ncMeta)).find((col) => col.id === kanbanView.fk_grp_col_id,@@ -384,8 +425,13 @@ export class KanbansService {},},req: param.req,+ viewWebhookManager,},ncMeta,);++ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(modelView.id)).emit();+ }}}diff --git a/packages/nocodb/src/services/sorts.service.ts b/packages/nocodb/src/services/sorts.service.tsindex b4e44d52da..9c69135fba 100644--- a/packages/nocodb/src/services/sorts.service.ts+++ b/packages/nocodb/src/services/sorts.service.ts@@ -3,6 +3,10 @@ import { AppEvents, EventType } from 'nocodb-sdk';import type { SortReqType } from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';import { NcError } from '~/helpers/catchError';@@ -106,7 +110,12 @@ export class SortsService {async sortCreate(context: NcContext,- param: { viewId: string; sort: SortReqType; req: NcRequest },+ param: {+ viewId: string;+ sort: SortReqType;+ req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;+ },ncMeta?: MetaService,) {validatePayload('swagger.json#/components/schemas/SortReq', param.sort);@@ -125,6 +134,15 @@ export class SortsService {if (!view) {NcError.badRequest('View not found');}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(view.id)+ ).forUpdate();const column = await Column.get(context,@@ -151,6 +169,9 @@ export class SortsService {},context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(view.id)).emit();+ }return sort;}diff --git a/packages/nocodb/src/services/v3/filters-v3.service.ts b/packages/nocodb/src/services/v3/filters-v3.service.tsindex 3ac99f54a8..1c64fe926d 100644--- a/packages/nocodb/src/services/v3/filters-v3.service.ts+++ b/packages/nocodb/src/services/v3/filters-v3.service.ts@@ -1,5 +1,4 @@import { Injectable } from '@nestjs/common';-import RowColorCondition from 'src/models/RowColorCondition';import type {FilterCreateV3Type,FilterGroupV3Type,@@ -11,6 +10,9 @@ import type {} from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';+import type { ViewWebhookManager } from '~/utils/view-webhook-manager';+import { ViewWebhookManagerBuilder } from '~/utils/view-webhook-manager';+import RowColorCondition from '~/models/RowColorCondition';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { NcError } from '~/helpers/catchError';import { Filter, Hook, View } from '~/models';@@ -127,6 +129,7 @@ export class FiltersV3Service {logicalOp = null,isRoot = true, // Flag to check if it's the root groupviewId,+ viewWebhookManager,ncMeta,}: {context: any;@@ -140,6 +143,7 @@ export class FiltersV3Service {logicalOp?: 'AND' | 'OR' | null;isRoot?: boolean;viewId: string;+ viewWebhookManager?: ViewWebhookManager;ncMeta?: MetaService;}): Promise<void> {validatePayload(@@ -154,6 +158,20 @@ export class FiltersV3Service {param,context,);+ let innerViewWebhookManager: ViewWebhookManager;++ if ((param as any).viewId && !viewWebhookManager) {+ const view = await View.get(context, (param as any).viewId, ncMeta);+ innerViewWebhookManager = (param as any).viewId+ ? (+ await (+ await new ViewWebhookManagerBuilder(context, ncMeta).withModelId(+ view.fk_model_id,+ )+ ).withViewId(view.id)+ ).forUpdate()+ : null;+ }// if logicalOp is not provided, extract based on the parent groupif (!logicalOp) {@@ -292,6 +310,12 @@ export class FiltersV3Service {} else {throw new Error('Invalid structure: Expected a group or filter.');}++ if (innerViewWebhookManager) {+ (+ await innerViewWebhookManager.withNewViewId((param as any).viewId)+ ).emit();+ }}private async extractAdditionalProps(@@ -517,6 +541,7 @@ export class FiltersV3Service {});}+ // skip viewWebhookManager for this, deleteAll is not a standalone operation, it's invoked by view serviceasync filterDeleteAll(context: NcContext,param: {diff --git a/packages/nocodb/src/services/v3/sorts-v3.service.ts b/packages/nocodb/src/services/v3/sorts-v3.service.tsindex 654eea36dd..784b91496b 100644--- a/packages/nocodb/src/services/v3/sorts-v3.service.ts+++ b/packages/nocodb/src/services/v3/sorts-v3.service.ts@@ -7,6 +7,7 @@ import type {} from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';import type { MetaService } from '~/meta/meta.service';+import { type ViewWebhookManager } from '~/utils/view-webhook-manager';import { Column, Sort } from '~/models';import { SortsService } from '~/services/sorts.service';import {@@ -55,6 +56,7 @@ export class SortsV3Service {sort: SortUpdateV3Type;req: NcRequest;viewId: string;+ viewWebhookManager?: ViewWebhookManager;},) {validatePayload(@@ -87,7 +89,12 @@ export class SortsV3Service {async sortCreate(context: NcContext,- param: { viewId: string; sort: SortCreateV3Type; req: NcRequest },+ param: {+ viewId: string;+ sort: SortCreateV3Type;+ req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;+ },ncMeta?: MetaService,) {validatePayload(@@ -124,6 +131,7 @@ export class SortsV3Service {{...param,sort: this.revBuilder().build(param.sort) as SortReqType,+ viewWebhookManager: param.viewWebhookManager,},ncMeta,);diff --git a/packages/nocodb/src/services/views.service.ts b/packages/nocodb/src/services/views.service.tsindex 368db11826..fcafe8e370 100644--- a/packages/nocodb/src/services/views.service.ts+++ b/packages/nocodb/src/services/views.service.ts@@ -6,6 +6,10 @@ import type {ViewUpdateReqType,} from 'nocodb-sdk';import type { NcContext, NcRequest } from '~/interface/config';+import {+ type ViewWebhookManager,+ ViewWebhookManagerBuilder,+} from '~/utils/view-webhook-manager';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';import { NcError } from '~/helpers/catchError';@@ -148,6 +152,7 @@ export class ViewsService {view: ViewUpdateReqType;user: UserType;req: NcRequest;+ viewWebhookManager?: ViewWebhookManager;},) {validatePayload(@@ -160,6 +165,16 @@ export class ViewsService {NcError.viewNotFound(param.viewId);}+ const viewWebhookManager =+ param.viewWebhookManager ??+ (+ await (+ await new ViewWebhookManagerBuilder(context).withModelId(+ oldView.fk_model_id,+ )+ ).withViewId(param.viewId)+ ).forUpdate();+let ownedBy = oldView.owned_by;let createdBy = oldView.created_by;let includeCreatedByAndUpdateBy = false;@@ -260,6 +275,10 @@ export class ViewsService {context.socket_id,);+ if (!param.viewWebhookManager) {+ (await viewWebhookManager.withNewViewId(oldView.id)).emit();+ }+return result;}diff --git a/packages/nocodb/src/utils/view-webhook-manager.ts b/packages/nocodb/src/utils/view-webhook-manager.tsindex 67772101ed..19660b1928 100644--- a/packages/nocodb/src/utils/view-webhook-manager.ts+++ b/packages/nocodb/src/utils/view-webhook-manager.ts@@ -39,6 +39,7 @@ export class ViewWebhookManagerBuilder {}async withView(view: any) {this.oldView = view;+ return this;}async withViewId(viewId: string, req?: NcRequest) {// needed to prevent circular dependencies@@ -51,6 +52,7 @@ export class ViewWebhookManagerBuilder {},this.ncMeta,);+ return this;}forCreate() {