From f7fdedbca6f747e872d3a130f0c707745e4b6aa4 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 2 Mar 2023 13:56:50 +0530 Subject: [PATCH] fix: type corrections Signed-off-by: Pranav C --- packages/nocodb-sdk/src/lib/Api.ts | 52 +- packages/nocodb/package-lock.json | 14 +- packages/nocodb/package.json | 2 +- packages/nocodb/src/lib/Noco.ts | 8 +- .../src/lib/controllers/columnController.ts | 25 +- .../dataApis/dataAliasExportApis.ts | 2 +- .../src/lib/controllers/dataApis/helpers.ts | 161 ++--- .../lib/controllers/dataController/export.ts | 10 +- .../lib/controllers/hookFilterController.ts | 130 ++-- .../lib/controllers/kanbanViewController.ts | 6 +- .../lib/controllers/orgLicenseController.ts | 2 +- .../src/lib/controllers/pluginController.ts | 11 +- .../src/lib/controllers/projectController.ts | 10 +- .../src/lib/controllers/public/index.ts | 6 +- .../src/lib/controllers/sortController.ts | 2 +- .../controllers/swaggerController/index.ts | 30 +- .../src/lib/controllers/sync/helpers/job.ts | 6 +- .../lib/controllers/sync/syncSourceApis.ts | 16 +- .../src/lib/controllers/tableController.ts | 2 +- .../controllers/userApi/initAdminFromEnv.ts | 16 +- .../src/lib/controllers/userApi/userApis.ts | 30 +- .../lib/controllers/userController/index.ts | 4 +- .../src/lib/controllers/viewController.ts | 5 +- .../src/lib/db/sql-client/lib/KnexClient.ts | 4 +- packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts | 4 +- packages/nocodb/src/lib/meta/NcMetaMgr.ts | 48 +- packages/nocodb/src/lib/meta/NcMetaMgrEE.ts | 8 +- .../nocodb/src/lib/meta/api/projectApis.ts | 0 .../nocodb/src/lib/meta/helpers/apiMetrics.ts | 4 +- packages/nocodb/src/lib/models/GalleryView.ts | 2 +- packages/nocodb/src/lib/models/Hook.ts | 166 +++-- packages/nocodb/src/lib/models/KanbanView.ts | 8 +- packages/nocodb/src/lib/models/Model.ts | 577 +++++++++--------- packages/nocodb/src/lib/models/Project.ts | 2 +- .../src/lib/services/apiTokenService.ts | 6 +- .../src/lib/services/attachmentService.ts | 6 +- .../nocodb/src/lib/services/baseService.ts | 10 +- .../nocodb/src/lib/services/cacheService.ts | 6 +- .../nocodb/src/lib/services/columnService.ts | 50 +- .../src/lib/services/dataService/export.ts | 30 +- .../src/lib/services/dataService/helpers.ts | 172 ++---- .../src/lib/services/dataService/index.ts | 5 +- .../nocodb/src/lib/services/filterService.ts | 57 +- .../src/lib/services/formViewColumnService.ts | 4 +- .../src/lib/services/formViewService.ts | 6 +- .../src/lib/services/galleryViewService.ts | 8 +- .../src/lib/services/gridViewColumnService.ts | 4 +- .../src/lib/services/gridViewService.ts | 6 +- .../src/lib/services/hookFilterService.ts | 8 +- .../nocodb/src/lib/services/hookService.ts | 16 +- .../src/lib/services/kanbanViewService.ts | 6 +- .../nocodb/src/lib/services/mapViewService.ts | 25 +- .../src/lib/services/metaDiffService.ts | 10 +- .../lib/services/modelVisibilityService.ts | 6 +- .../src/lib/services/orgLicenseService.ts | 8 +- .../src/lib/services/orgTokenService.ts | 6 +- .../nocodb/src/lib/services/orgUserService.ts | 4 +- .../nocodb/src/lib/services/pluginService.ts | 29 +- .../nocodb/src/lib/services/projectService.ts | 14 +- .../src/lib/services/projectUserService.ts | 4 +- .../src/lib/services/sharedBaseService.ts | 17 +- .../nocodb/src/lib/services/sortService.ts | 9 +- .../services/swaggerService/getSwaggerJSON.ts | 2 +- .../src/lib/services/swaggerService/index.ts | 13 +- .../lib/services/syncService/helpers/job.ts | 6 +- .../src/lib/services/syncService/index.ts | 18 +- .../nocodb/src/lib/services/tableService.ts | 9 +- .../src/lib/services/userService/helpers.ts | 4 +- .../src/lib/services/userService/index.ts | 87 ++- .../services/userService/initAdminFromEnv.ts | 15 +- .../userService/ui/auth/emailVerify.ts | 70 +++ .../userService/ui/auth/resetPassword.ts | 108 ++++ .../ui/emailTemplates/forgotPassword.ts | 171 ++++++ .../userService/ui/emailTemplates/invite.ts | 208 +++++++ .../userService/ui/emailTemplates/verify.ts | 207 +++++++ .../nocodb/src/lib/services/utilService.ts | 4 +- .../src/lib/services/viewColumnService.ts | 8 +- .../nocodb/src/lib/services/viewService.ts | 32 +- .../src/lib/utils/common/BaseApiBuilder.ts | 6 +- .../src/lib/v1-legacy/NcProjectBuilder.ts | 4 +- .../src/lib/v1-legacy/rest/RestAuthCtrl.ts | 18 +- .../src/lib/v1-legacy/rest/RestAuthCtrlEE.ts | 4 +- .../src/lib/version-upgrader/NcUpgrader.ts | 6 +- 83 files changed, 1788 insertions(+), 1117 deletions(-) create mode 100644 packages/nocodb/src/lib/meta/api/projectApis.ts create mode 100644 packages/nocodb/src/lib/services/userService/ui/auth/emailVerify.ts create mode 100644 packages/nocodb/src/lib/services/userService/ui/auth/resetPassword.ts create mode 100644 packages/nocodb/src/lib/services/userService/ui/emailTemplates/forgotPassword.ts create mode 100644 packages/nocodb/src/lib/services/userService/ui/emailTemplates/invite.ts create mode 100644 packages/nocodb/src/lib/services/userService/ui/emailTemplates/verify.ts diff --git a/packages/nocodb-sdk/src/lib/Api.ts b/packages/nocodb-sdk/src/lib/Api.ts index c2197a21be..a1017e4b07 100644 --- a/packages/nocodb-sdk/src/lib/Api.ts +++ b/packages/nocodb-sdk/src/lib/Api.ts @@ -651,7 +651,7 @@ export interface HookReqType { env?: string; event: 'after' | 'before'; operation: 'insert' | 'delete' | 'update'; - async?: string | number | null; + async?: BoolType; notification: object; retries?: number; retry_interval?: number; @@ -1095,8 +1095,8 @@ export class Api< > extends HttpClient { auth = { /** - * @description Create a new user with provided email and password and first user is marked as super admin. - * + * @description Create a new user with provided email and password and first user is marked as super admin. + * * @tags Auth * @name Signup * @summary Signup @@ -1130,7 +1130,7 @@ export class Api< /** * @description Clear refresh token from the database and cookie. - * + * * @tags Auth * @name Signout * @summary Signout @@ -1154,8 +1154,8 @@ export class Api< }), /** - * @description Authenticate existing user with their email and password. Successful login will return a JWT access-token. - * + * @description Authenticate existing user with their email and password. Successful login will return a JWT access-token. + * * @tags Auth * @name Signin * @summary Signin @@ -1231,7 +1231,7 @@ export class Api< /** * @description Change password of authenticated user with a new one. - * + * * @tags Auth * @name PasswordChange * @summary Password change @@ -1334,7 +1334,7 @@ export class Api< /** * No description - * + * * @tags Auth * @name ProjectUserList * @summary Project users @@ -1455,7 +1455,7 @@ export class Api< orgTokens = { /** * No description - * + * * @tags Org tokens * @name List * @summary Organisation API Tokens List @@ -1525,7 +1525,7 @@ export class Api< orgLicense = { /** * No description - * + * * @tags Org license * @name Get * @summary App license get @@ -1569,7 +1569,7 @@ export class Api< orgAppSettings = { /** * No description - * + * * @tags Org app settings * @name Get * @summary App settings get @@ -1618,7 +1618,7 @@ export class Api< orgUsers = { /** * No description - * + * * @tags Org users * @name List * @summary Organisation Users @@ -1723,7 +1723,7 @@ export class Api< /** * No description - * + * * @tags Org users * @name GeneratePasswordResetToken * @summary Organisation User Generate Password Reset Token @@ -1751,7 +1751,7 @@ export class Api< project = { /** * No description - * + * * @tags Project * @name MetaGet * @summary Project info @@ -1936,7 +1936,7 @@ export class Api< /** * @description Read project details - * + * * @tags Project * @name SharedBaseGet * @request GET:/api/v1/db/meta/projects/{projectId}/shared @@ -2004,7 +2004,7 @@ export class Api< /** * No description - * + * * @tags Project * @name SharedBaseUpdate * @request PATCH:/api/v1/db/meta/projects/{projectId}/shared @@ -2106,7 +2106,7 @@ export class Api< /** * No description - * + * * @tags Project * @name AuditList * @request GET:/api/v1/db/meta/projects/{projectId}/audits @@ -2998,7 +2998,7 @@ export class Api< /** * No description - * + * * @tags DB view share * @name Create * @request POST:/api/v1/db/meta/views/{viewId}/share @@ -3117,7 +3117,7 @@ export class Api< dbTableSort = { /** * No description - * + * * @tags DB table sort * @name List * @request GET:/api/v1/db/meta/views/{viewId}/sorts @@ -4318,7 +4318,7 @@ export class Api< /** * @description Read project details - * + * * @tags Public * @name SharedBaseGet * @request GET:/api/v1/db/public/shared-base/{sharedBaseUuid}/meta @@ -4342,7 +4342,7 @@ export class Api< /** * No description - * + * * @tags Public * @name SharedViewMetaGet * @request GET:/api/v1/db/public/shared-view/{sharedViewUuid}/meta @@ -4475,7 +4475,7 @@ export class Api< /** * No description - * + * * @tags Utils * @name TestConnection * @request POST:/api/v1/db/meta/connection/test @@ -4585,7 +4585,7 @@ export class Api< /** * No description - * + * * @tags Utils * @name AggregatedMetaInfo * @request GET:/api/v1/aggregated-meta-info @@ -4702,7 +4702,7 @@ export class Api< dbTableWebhook = { /** * No description - * + * * @tags DB table webhook * @name List * @request GET:/api/v1/db/meta/tables/{tableId}/hooks @@ -4768,7 +4768,7 @@ export class Api< /** * No description - * + * * @tags DB table webhook * @name SamplePayloadGet * @request GET:/api/v1/db/meta/tables/{tableId}/hooks/samplePayload/{operation} @@ -4837,7 +4837,7 @@ export class Api< plugin = { /** * No description - * + * * @tags Plugin * @name List * @request GET:/api/v1/db/meta/plugins diff --git a/packages/nocodb/package-lock.json b/packages/nocodb/package-lock.json index 1f94426e0a..4950e351b1 100644 --- a/packages/nocodb/package-lock.json +++ b/packages/nocodb/package-lock.json @@ -65,7 +65,7 @@ "multer": "^1.4.2", "mysql2": "^2.2.5", "nanoid": "^3.1.20", - "nc-help": "0.2.85", + "nc-help": "0.2.87", "nc-lib-gui": "0.105.3", "nc-plugin": "0.1.2", "ncp": "^2.0.0", @@ -11294,9 +11294,9 @@ } }, "node_modules/nc-help": { - "version": "0.2.85", - "resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.85.tgz", - "integrity": "sha512-EOyrc2PuRUJzv73jHNHmUR6YhC0TlJG0DTY/sug7BF4MJAVPJgyavJnrqkRC7g0NS4xociki9gs5MbLRjlRwtQ==", + "version": "0.2.87", + "resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.87.tgz", + "integrity": "sha512-Zlg06ialvylBEE1qtvjlNKxZrPShzXwvy3WG7nfw+8GngOkQBCTlKguejT2Kq4Gfb5378WPX1APXtsetMKBrRA==", "dependencies": { "@rudderstack/rudder-sdk-node": "^1.1.3", "axios": "^0.21.1", @@ -28004,9 +28004,9 @@ "integrity": "sha512-3AryS9uwa5NfISLxMciUonrH7YfXp+nlahB9T7girXIsLQrmwX4MdnuKs32akduCOGpKmjTJSWmATULbuMkbfw==" }, "nc-help": { - "version": "0.2.85", - "resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.85.tgz", - "integrity": "sha512-EOyrc2PuRUJzv73jHNHmUR6YhC0TlJG0DTY/sug7BF4MJAVPJgyavJnrqkRC7g0NS4xociki9gs5MbLRjlRwtQ==", + "version": "0.2.87", + "resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.87.tgz", + "integrity": "sha512-Zlg06ialvylBEE1qtvjlNKxZrPShzXwvy3WG7nfw+8GngOkQBCTlKguejT2Kq4Gfb5378WPX1APXtsetMKBrRA==", "requires": { "@rudderstack/rudder-sdk-node": "^1.1.3", "axios": "^0.21.1", diff --git a/packages/nocodb/package.json b/packages/nocodb/package.json index 0b77966f58..9682e923c6 100644 --- a/packages/nocodb/package.json +++ b/packages/nocodb/package.json @@ -105,7 +105,7 @@ "multer": "^1.4.2", "mysql2": "^2.2.5", "nanoid": "^3.1.20", - "nc-help": "0.2.85", + "nc-help": "0.2.87", "nc-lib-gui": "0.105.3", "nc-plugin": "0.1.2", "ncp": "^2.0.0", diff --git a/packages/nocodb/src/lib/Noco.ts b/packages/nocodb/src/lib/Noco.ts index 00b80d421b..ca4ae28486 100644 --- a/packages/nocodb/src/lib/Noco.ts +++ b/packages/nocodb/src/lib/Noco.ts @@ -21,7 +21,7 @@ import { NC_LICENSE_KEY } from './constants'; import Migrator from './db/sql-migrator/lib/KnexMigrator'; import Store from './models/Store'; import NcConfigFactory from './utils/NcConfigFactory'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import NcProjectBuilderCE from './v1-legacy/NcProjectBuilder'; import NcProjectBuilderEE from './v1-legacy/NcProjectBuilderEE'; @@ -275,10 +275,10 @@ export default class Noco { } next(); }); - Tele.init({ + T.init({ instance: getInstance, }); - Tele.emit('evt_app_started', await User.count()); + T.emit('evt_app_started', await User.count()); console.log(`App started successfully.\nVisit -> ${Noco.dashboardUrl}`); weAreHiring(); return this.router; @@ -531,7 +531,7 @@ export default class Noco { if (!serverId) { await Noco._ncMeta.metaInsert('', '', 'nc_store', { key: 'nc_server_id', - value: (serverId = Tele.id), + value: (serverId = T.id), }); } process.env.NC_SERVER_UUID = serverId; diff --git a/packages/nocodb/src/lib/controllers/columnController.ts b/packages/nocodb/src/lib/controllers/columnController.ts index dad4a4c01b..61f2e0139d 100644 --- a/packages/nocodb/src/lib/controllers/columnController.ts +++ b/packages/nocodb/src/lib/controllers/columnController.ts @@ -1,8 +1,8 @@ -import { Request, Response, Router } from 'express' +import { Request, Response, Router } from 'express'; import { ColumnReqType, TableType, UITypes } from 'nocodb-sdk'; -import { getAjvValidatorMw } from '../meta/api/helpers' -import { metaApiMetrics } from '../meta/helpers/apiMetrics' -import ncMetaAclMw from '../meta/helpers/ncMetaAclMw' +import { getAjvValidatorMw } from '../meta/api/helpers'; +import { metaApiMetrics } from '../meta/helpers/apiMetrics'; +import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; import { columnService } from '../services'; export async function columnGet(req: Request, res: Response) { @@ -27,20 +27,19 @@ export async function columnSetAsPrimary(req: Request, res: Response) { ); } - - -export async function columnUpdate(req: Request, res: Response){ - res.json(await columnService.columnUpdate({ - columnId: req.params.columnId, - column: req.body - }) +export async function columnUpdate(req: Request, res: Response) { + res.json( + await columnService.columnUpdate({ + columnId: req.params.columnId, + column: req.body, + }) + ); } export async function columnDelete(req: Request, res: Response) { - res.json(await columnService.columnDelete({ columnId: req.params.columnId })); + res.json(await columnService.columnDelete({ columnId: req.params.columnId })); } - const router = Router({ mergeParams: true }); router.post( diff --git a/packages/nocodb/src/lib/controllers/dataApis/dataAliasExportApis.ts b/packages/nocodb/src/lib/controllers/dataApis/dataAliasExportApis.ts index 8593ff6fa9..f0f145f596 100644 --- a/packages/nocodb/src/lib/controllers/dataApis/dataAliasExportApis.ts +++ b/packages/nocodb/src/lib/controllers/dataApis/dataAliasExportApis.ts @@ -15,7 +15,7 @@ async function excelDataExport(req: Request, res: Response) { if (!targetView) { targetView = await View.getDefaultView(model.id); } - const { offset, elapsed, data } = await extractXlsxData(targetView, req); + const { offset, elapsed, data } = await extractXlsxData({ view: targetView, query: req.query, siteUrl: (req as any).ncSiteUrl }); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, data, targetView.title); const buf = XLSX.write(wb, { type: 'base64', bookType: 'xlsx' }); diff --git a/packages/nocodb/src/lib/controllers/dataApis/helpers.ts b/packages/nocodb/src/lib/controllers/dataApis/helpers.ts index ed48507e0d..1a7216f5fc 100644 --- a/packages/nocodb/src/lib/controllers/dataApis/helpers.ts +++ b/packages/nocodb/src/lib/controllers/dataApis/helpers.ts @@ -1,20 +1,19 @@ -import Project from '../../models/Project'; -import Model from '../../models/Model'; -import View from '../../models/View'; -import { NcError } from '../../meta/helpers/catchError'; +import Project from '../../../models/Project'; +import Model from '../../../models/Model'; +import View from '../../../models/View'; +import { NcError } from '../../helpers/catchError'; import { Request } from 'express'; -import Base from '../../models/Base'; -import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2'; +import Base from '../../../models/Base'; +import NcConnectionMgrv2 from '../../../utils/common/NcConnectionMgrv2'; import { isSystemColumn, UITypes } from 'nocodb-sdk'; -import { nocoExecute } from 'nc-help'; import * as XLSX from 'xlsx'; -import Column from '../../models/Column'; -import LookupColumn from '../../models/LookupColumn'; -import LinkToAnotherRecordColumn from '../../models/LinkToAnotherRecordColumn'; +import Column from '../../../models/Column'; +import LookupColumn from '../../../models/LookupColumn'; +import LinkToAnotherRecordColumn from '../../../models/LinkToAnotherRecordColumn'; import papaparse from 'papaparse'; -import getAst from '../../db/sql-data-mapper/lib/sql/helpers/getAst'; +import { dataService } from '../../../services'; export async function getViewAndModelFromRequestByAliasOrId( req: | Request<{ projectName: string; tableName: string; viewName?: string }> @@ -36,8 +35,12 @@ export async function getViewAndModelFromRequestByAliasOrId( return { model, view }; } -export async function extractXlsxData(param: {view: View, query:any}) { - const { view, query } = param; +export async function extractXlsxData(param: { + view: View; + query: any; + siteUrl: string; +}) { + const { view, query, siteUrl } = param; const base = await Base.get(view.base_id); await view.getModelWithInfo(); @@ -57,9 +60,14 @@ export async function extractXlsxData(param: {view: View, query:any}) { dbDriver: NcConnectionMgrv2.get(base), }); - const { offset, dbRows, elapsed } = await getDbRows(baseModel, view, req); + const { offset, dbRows, elapsed } = await dataService.getDbRows({ + baseModel, + view, + query, + siteUrl, + }); - const fields = req.query.fields as string[]; + const fields = query.fields as string[]; const data = XLSX.utils.json_to_sheet(dbRows, { header: fields }); @@ -87,7 +95,12 @@ export async function extractCsvData(view: View, req: Request) { dbDriver: NcConnectionMgrv2.get(base), }); - const { offset, dbRows, elapsed } = await getDbRows(baseModel, view, req); + const { offset, dbRows, elapsed } = await dataService.getDbRows({ + baseModel, + view, + query: req.query, + siteUrl: (req as any).ncSiteUrl, + }); const data = papaparse.unparse( { @@ -111,64 +124,64 @@ export async function extractCsvData(view: View, req: Request) { return { offset, dbRows, elapsed, data }; } - -async function getDbRows(baseModel, view: View, req: Request) { - let offset = +req.query.offset || 0; - const limit = 100; - // const size = +process.env.NC_EXPORT_MAX_SIZE || 1024; - const timeout = +process.env.NC_EXPORT_MAX_TIMEOUT || 5000; - const dbRows = []; - const startTime = process.hrtime(); - let elapsed, temp; - - const listArgs: any = { ...req.query }; - try { - listArgs.filterArr = JSON.parse(listArgs.filterArrJson); - } catch (e) {} - try { - listArgs.sortArr = JSON.parse(listArgs.sortArrJson); - } catch (e) {} - - for ( - elapsed = 0; - elapsed < timeout; - offset += limit, - temp = process.hrtime(startTime), - elapsed = temp[0] * 1000 + temp[1] / 1000000 - ) { - const rows = await nocoExecute( - await getAst({ - query: req.query, - includePkByDefault: false, - model: view.model, - view, - }), - await baseModel.list({ ...listArgs, offset, limit }), - {}, - req.query - ); - - if (!rows?.length) { - offset = -1; - break; - } - - for (const row of rows) { - const dbRow = { ...row }; - - for (const column of view.model.columns) { - if (isSystemColumn(column) && !view.show_system_fields) continue; - dbRow[column.title] = await serializeCellValue({ - value: row[column.title], - column, - siteUrl: req['ncSiteUrl'], - }); - } - dbRows.push(dbRow); - } - } - return { offset, dbRows, elapsed }; -} +// +// async function getDbRows(baseModel, view: View, req: Request) { +// let offset = +req.query.offset || 0; +// const limit = 100; +// // const size = +process.env.NC_EXPORT_MAX_SIZE || 1024; +// const timeout = +process.env.NC_EXPORT_MAX_TIMEOUT || 5000; +// const dbRows = []; +// const startTime = process.hrtime(); +// let elapsed, temp; +// +// const listArgs: any = { ...req.query }; +// try { +// listArgs.filterArr = JSON.parse(listArgs.filterArrJson); +// } catch (e) {} +// try { +// listArgs.sortArr = JSON.parse(listArgs.sortArrJson); +// } catch (e) {} +// +// for ( +// elapsed = 0; +// elapsed < timeout; +// offset += limit, +// temp = process.hrtime(startTime), +// elapsed = temp[0] * 1000 + temp[1] / 1000000 +// ) { +// const rows = await nocoExecute( +// await getAst({ +// query: req.query, +// includePkByDefault: false, +// model: view.model, +// view, +// }), +// await baseModel.list({ ...listArgs, offset, limit }), +// {}, +// req.query +// ); +// +// if (!rows?.length) { +// offset = -1; +// break; +// } +// +// for (const row of rows) { +// const dbRow = { ...row }; +// +// for (const column of view.model.columns) { +// if (isSystemColumn(column) && !view.show_system_fields) continue; +// dbRow[column.title] = await serializeCellValue({ +// value: row[column.title], +// column, +// siteUrl: req['ncSiteUrl'], +// }); +// } +// dbRows.push(dbRow); +// } +// } +// return { offset, dbRows, elapsed }; +// } export async function serializeCellValue({ value, diff --git a/packages/nocodb/src/lib/controllers/dataController/export.ts b/packages/nocodb/src/lib/controllers/dataController/export.ts index 8c6cf38bea..05f77dde5c 100644 --- a/packages/nocodb/src/lib/controllers/dataController/export.ts +++ b/packages/nocodb/src/lib/controllers/dataController/export.ts @@ -1,13 +1,13 @@ import { Request, Response, Router } from 'express'; import * as XLSX from 'xlsx'; -import ncMetaAclMw from '../../helpers/ncMetaAclMw'; +import { getViewAndModelFromRequestByAliasOrId } from '../../meta/api/dataApis/helpers'; +import apiMetrics from '../../meta/helpers/apiMetrics'; +import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; +import { View } from '../../models'; import { extractCsvData, extractXlsxData, - getViewAndModelFromRequestByAliasOrId, -} from './helpers'; -import apiMetrics from '../../helpers/apiMetrics'; -import View from '../../../models/View'; +} from '../../services/dataService/helpers'; async function excelDataExport(req: Request, res: Response) { const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); diff --git a/packages/nocodb/src/lib/controllers/hookFilterController.ts b/packages/nocodb/src/lib/controllers/hookFilterController.ts index 0d0aa0a8da..71e3977802 100644 --- a/packages/nocodb/src/lib/controllers/hookFilterController.ts +++ b/packages/nocodb/src/lib/controllers/hookFilterController.ts @@ -1,112 +1,60 @@ import { Request, Response, Router } from 'express'; -// @ts-ignore -import Model from '../models/Model'; -import { Tele } from 'nc-help'; -// @ts-ignore -import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; -// @ts-ignore -import { Table, TableList, TableListParams, TableReq } from 'nocodb-sdk'; -// @ts-ignore -import ProjectMgrv2 from '../db/sql-mgr/v2/ProjectMgrv2'; -// @ts-ignore -import Project from '../models/Project'; -import Filter from '../models/Filter'; +import { T } from 'nc-help'; import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; import { metaApiMetrics } from '../meta/helpers/apiMetrics'; import { getAjvValidatorMw } from '../meta/api/helpers'; +import { hookFilterService } from '../services'; -// @ts-ignore -export async function filterGet(req: Request, res: Response, next) { - try { - const filter = await Filter.getFilterObject({ hookId: req.params.hookId }); +export async function filterGet(req: Request, res: Response) { + const filter = await hookFilterService.filterGet({ + hookId: req.params.hookId, + }); - res.json(filter); - } catch (e) { - console.log(e); - next(e); - } + res.json(filter); } -// @ts-ignore -export async function filterList( - req: Request, - res: Response, - next -) { - try { - const filter = await Filter.rootFilterListByHook({ - hookId: req.params.hookId, - }); +export async function filterList(req: Request, res: Response) { + const filter = await hookFilterService.filterList({ + hookId: req.params.hookId, + }); - res.json(filter); - } catch (e) { - console.log(e); - next(e); - } + res.json(filter); } -// @ts-ignore -export async function filterChildrenRead( - req: Request, - res: Response, - next -) { - try { - const filter = await Filter.parentFilterListByHook({ - hookId: req.params.hookId, - parentId: req.params.filterParentId, - }); - res.json(filter); - } catch (e) { - console.log(e); - next(e); - } +export async function filterChildrenRead(req: Request, res: Response) { + const filter = await hookFilterService.filterChildrenRead({ + hookId: req.params.hookId, + filterParentId: req.params.filterParentId, + }); + + res.json(filter); } -export async function filterCreate( - req: Request, - res, - next -) { - try { - const filter = await Filter.insert({ - ...req.body, - fk_hook_id: req.params.hookId, - }); +export async function filterCreate(req: Request, res) { + const filter = await hookFilterService.filterCreate({ + filter: req.body, + hookId: req.params.hookId, + }); - Tele.emit('evt', { evt_type: 'hookFilter:created' }); - res.json(filter); - } catch (e) { - console.log(e); - next(e); - } + res.json(filter); } -// @ts-ignore -export async function filterUpdate(req, res, next) { - try { - const filter = await Filter.update(req.params.filterId, { - ...req.body, - fk_hook_id: req.params.hookId, - }); - Tele.emit('evt', { evt_type: 'hookFilter:updated' }); - res.json(filter); - } catch (e) { - console.log(e); - next(e); - } +export async function filterUpdate(req, res) { + const filter = await hookFilterService.filterUpdate({ + filterId: req.params.filterId, + filter: req.body, + hookId: req.params.hookId, + }); + + res.json(filter); } -// @ts-ignore -export async function filterDelete(req: Request, res: Response, next) { - try { - const filter = await Filter.delete(req.params.filterId); - Tele.emit('evt', { evt_type: 'hookFilter:deleted' }); - res.json(filter); - } catch (e) { - console.log(e); - next(e); - } +export async function filterDelete(req: Request, res: Response) { + const filter = await hookFilterService.filterDelete({ + filterId: req.params.filterId, + }); + T.emit('evt', { evt_type: 'hookFilter:deleted' }); + res.json(filter); } const router = Router({ mergeParams: true }); diff --git a/packages/nocodb/src/lib/controllers/kanbanViewController.ts b/packages/nocodb/src/lib/controllers/kanbanViewController.ts index e9db2a3afb..7ea705e6bb 100644 --- a/packages/nocodb/src/lib/controllers/kanbanViewController.ts +++ b/packages/nocodb/src/lib/controllers/kanbanViewController.ts @@ -2,7 +2,7 @@ import { Request, Response, Router } from 'express'; import { KanbanType, ViewTypes } from 'nocodb-sdk'; import View from '../models/View'; import KanbanView from '../models/KanbanView'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; import { metaApiMetrics } from '../meta/helpers/apiMetrics'; import { getAjvValidatorMw } from '../meta/api/helpers'; @@ -12,7 +12,7 @@ export async function kanbanViewGet(req: Request, res: Response) { } export async function kanbanViewCreate(req: Request, res) { - Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' }); + T.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' }); const view = await View.insert({ ...req.body, // todo: sanitize @@ -23,7 +23,7 @@ export async function kanbanViewCreate(req: Request, res) { } export async function kanbanViewUpdate(req, res) { - Tele.emit('evt', { evt_type: 'view:updated', type: 'kanban' }); + T.emit('evt', { evt_type: 'view:updated', type: 'kanban' }); res.json(await KanbanView.update(req.params.kanbanViewId, req.body)); } diff --git a/packages/nocodb/src/lib/controllers/orgLicenseController.ts b/packages/nocodb/src/lib/controllers/orgLicenseController.ts index 02b167c3df..de6d839537 100644 --- a/packages/nocodb/src/lib/controllers/orgLicenseController.ts +++ b/packages/nocodb/src/lib/controllers/orgLicenseController.ts @@ -10,7 +10,7 @@ async function licenseGet(_req, res) { } async function licenseSet(req, res) { - await orgLicenseService.licenseSet({ key: req.body.key }) + await orgLicenseService.licenseSet({ key: req.body.key }); res.json({ msg: 'License key saved' }); } diff --git a/packages/nocodb/src/lib/controllers/pluginController.ts b/packages/nocodb/src/lib/controllers/pluginController.ts index c5bef7e9a0..156fce97db 100644 --- a/packages/nocodb/src/lib/controllers/pluginController.ts +++ b/packages/nocodb/src/lib/controllers/pluginController.ts @@ -6,8 +6,6 @@ import { metaApiMetrics } from '../meta/helpers/apiMetrics'; import { getAjvValidatorMw } from '../meta/api/helpers'; import { pluginService } from '../services'; - - export async function pluginList(_req: Request, res: Response) { res.json(new PagedResponseImpl(await pluginService.pluginList())); } @@ -23,11 +21,16 @@ export async function pluginUpdate( req: Request, res: Response ) { - const plugin = await pluginService.pluginUpdate({ pluginId: req.params.pluginId, plugin:req.body }); + const plugin = await pluginService.pluginUpdate({ + pluginId: req.params.pluginId, + plugin: req.body, + }); res.json(plugin); } export async function isPluginActive(req: Request, res: Response) { - res.json(await pluginService.isPluginActive({ pluginTitle: req.params.pluginTitle })); + res.json( + await pluginService.isPluginActive({ pluginTitle: req.params.pluginTitle }) + ); } const router = Router({ mergeParams: true }); diff --git a/packages/nocodb/src/lib/controllers/projectController.ts b/packages/nocodb/src/lib/controllers/projectController.ts index 5e65b8efdd..1be862a7e4 100644 --- a/packages/nocodb/src/lib/controllers/projectController.ts +++ b/packages/nocodb/src/lib/controllers/projectController.ts @@ -3,7 +3,7 @@ import { ProjectType } from 'nocodb-sdk'; import Project from '../models/Project'; import { ProjectListType } from 'nocodb-sdk'; import { packageVersion } from '../utils/packageVersion'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2'; import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; @@ -60,10 +60,7 @@ export async function projectList( ); } -export async function projectDelete( - req: Request, - res: Response -) { +export async function projectDelete(req: Request, res: Response) { const deleted = await projectService.projectSoftDelete({ projectId: req.params.projectId, }); @@ -71,7 +68,6 @@ export async function projectDelete( res.json(deleted); } - async function projectCreate(req: Request, res) { const project = await projectService.projectCreate({ project: req.body, @@ -116,7 +112,7 @@ export async function projectCost(req, res) { } } - Tele.event({ + T.event({ event: 'a:project:cost', data: { cost, diff --git a/packages/nocodb/src/lib/controllers/public/index.ts b/packages/nocodb/src/lib/controllers/public/index.ts index 60e7849dc2..8e1c237b36 100644 --- a/packages/nocodb/src/lib/controllers/public/index.ts +++ b/packages/nocodb/src/lib/controllers/public/index.ts @@ -2,4 +2,8 @@ import publicDataController from './publicDataApis'; import publicDataExportController from './publicDataExportApis'; import publicMetaController from './publicMetaApis'; -export { publicDataController, publicDataExportController, publicMetaController }; +export { + publicDataController, + publicDataExportController, + publicMetaController, +}; diff --git a/packages/nocodb/src/lib/controllers/sortController.ts b/packages/nocodb/src/lib/controllers/sortController.ts index c9ee69515a..397b605f57 100644 --- a/packages/nocodb/src/lib/controllers/sortController.ts +++ b/packages/nocodb/src/lib/controllers/sortController.ts @@ -1,5 +1,5 @@ import { Request, Response, Router } from 'express'; -import { getAjvValidatorMw } from '../meta/api/helpers' +import { getAjvValidatorMw } from '../meta/api/helpers'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; import { SortListType, SortReqType } from 'nocodb-sdk'; import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; diff --git a/packages/nocodb/src/lib/controllers/swaggerController/index.ts b/packages/nocodb/src/lib/controllers/swaggerController/index.ts index 1dba08f86f..1853e4c7ff 100644 --- a/packages/nocodb/src/lib/controllers/swaggerController/index.ts +++ b/packages/nocodb/src/lib/controllers/swaggerController/index.ts @@ -1,36 +1,36 @@ -import { Router } from 'express' -import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw' -import getSwaggerHtml from './swaggerHtml' -import getRedocHtml from './redocHtml' -import { swaggerService } from '../../services' +import { Router } from 'express'; +import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; +import getSwaggerHtml from './swaggerHtml'; +import getRedocHtml from './redocHtml'; +import { swaggerService } from '../../services'; async function swaggerJson(req, res) { const swagger = await swaggerService.swaggerJson({ projectId: req.params.projectId, siteUrl: req.ncSiteUrl, - }) + }); - res.json(swagger) + res.json(swagger); } function swaggerHtml(_, res) { - res.send(getSwaggerHtml({ ncSiteUrl: process.env.NC_PUBLIC_URL || '' })) + res.send(getSwaggerHtml({ ncSiteUrl: process.env.NC_PUBLIC_URL || '' })); } function redocHtml(_, res) { - res.send(getRedocHtml({ ncSiteUrl: process.env.NC_PUBLIC_URL || '' })) + res.send(getRedocHtml({ ncSiteUrl: process.env.NC_PUBLIC_URL || '' })); } -const router = Router({ mergeParams: true }) +const router = Router({ mergeParams: true }); // todo: auth router.get( '/api/v1/db/meta/projects/:projectId/swagger.json', - ncMetaAclMw(swaggerJson, 'swaggerJson'), -) + ncMetaAclMw(swaggerJson, 'swaggerJson') +); -router.get('/api/v1/db/meta/projects/:projectId/swagger', swaggerHtml) +router.get('/api/v1/db/meta/projects/:projectId/swagger', swaggerHtml); -router.get('/api/v1/db/meta/projects/:projectId/redoc', redocHtml) +router.get('/api/v1/db/meta/projects/:projectId/redoc', redocHtml); -export default router +export default router; diff --git a/packages/nocodb/src/lib/controllers/sync/helpers/job.ts b/packages/nocodb/src/lib/controllers/sync/helpers/job.ts index 2b4364ca05..9e55beb4bd 100644 --- a/packages/nocodb/src/lib/controllers/sync/helpers/job.ts +++ b/packages/nocodb/src/lib/controllers/sync/helpers/job.ts @@ -1,4 +1,4 @@ -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import FetchAT from './fetchAT'; import { UITypes } from 'nocodb-sdk'; // import * as sMap from './syncMap'; @@ -1924,7 +1924,7 @@ export default async ( }); } - Tele.event({ + T.event({ event: 'a:airtable-import:success', data: { stats: { @@ -2391,7 +2391,7 @@ export default async ( } } catch (e) { if (e.response?.data?.msg) { - Tele.event({ + T.event({ event: 'a:airtable-import:error', data: { error: e.response.data.msg }, }); diff --git a/packages/nocodb/src/lib/controllers/sync/syncSourceApis.ts b/packages/nocodb/src/lib/controllers/sync/syncSourceApis.ts index 2720f8fd88..9da8d70a70 100644 --- a/packages/nocodb/src/lib/controllers/sync/syncSourceApis.ts +++ b/packages/nocodb/src/lib/controllers/sync/syncSourceApis.ts @@ -1,10 +1,10 @@ import { Request, Response, Router } from 'express'; -import SyncSource from '../../models/SyncSource'; -import { Tele } from 'nc-help'; -import { PagedResponseImpl } from '../../meta/helpers/PagedResponse'; -import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; -import Project from '../../models/Project'; +import SyncSource from '../../../models/SyncSource'; +import { T } from 'nc-help'; +import { PagedResponseImpl } from '../../helpers/PagedResponse'; +import ncMetaAclMw from '../../helpers/ncMetaAclMw'; +import Project from '../../../models/Project'; export async function syncSourceList(req: Request, res: Response) { // todo: pagination @@ -16,7 +16,7 @@ export async function syncSourceList(req: Request, res: Response) { } export async function syncCreate(req: Request, res: Response) { - Tele.emit('evt', { evt_type: 'webhooks:created' }); + T.emit('evt', { evt_type: 'webhooks:created' }); const project = await Project.getWithInfo(req.params.projectId); const sync = await SyncSource.insert({ @@ -29,12 +29,12 @@ export async function syncCreate(req: Request, res: Response) { } export async function syncDelete(req: Request, res: Response) { - Tele.emit('evt', { evt_type: 'webhooks:deleted' }); + T.emit('evt', { evt_type: 'webhooks:deleted' }); res.json(await SyncSource.delete(req.params.syncId)); } export async function syncUpdate(req: Request, res: Response) { - Tele.emit('evt', { evt_type: 'webhooks:updated' }); + T.emit('evt', { evt_type: 'webhooks:updated' }); res.json(await SyncSource.update(req.params.syncId, req.body)); } diff --git a/packages/nocodb/src/lib/controllers/tableController.ts b/packages/nocodb/src/lib/controllers/tableController.ts index 8ee37c019f..df80818bff 100644 --- a/packages/nocodb/src/lib/controllers/tableController.ts +++ b/packages/nocodb/src/lib/controllers/tableController.ts @@ -42,7 +42,7 @@ export async function tableGet(req: Request, res: Response) { } export async function tableDelete(req: Request, res: Response) { - const result = await tableService.deleteTable({ + const result = await tableService.tableDelete({ tableId: req.params.tableId, user: (req as any).session?.passport?.user, }); diff --git a/packages/nocodb/src/lib/controllers/userApi/initAdminFromEnv.ts b/packages/nocodb/src/lib/controllers/userApi/initAdminFromEnv.ts index c39328bfb2..185fd155ae 100644 --- a/packages/nocodb/src/lib/controllers/userApi/initAdminFromEnv.ts +++ b/packages/nocodb/src/lib/controllers/userApi/initAdminFromEnv.ts @@ -1,15 +1,15 @@ -import User from '../../models/User'; +import User from '../../../models/User'; import { v4 as uuidv4 } from 'uuid'; import { promisify } from 'util'; import bcrypt from 'bcryptjs'; -import Noco from '../../Noco'; -import { CacheScope, MetaTable } from '../../utils/globals'; -import ProjectUser from '../../models/ProjectUser'; +import Noco from '../../../Noco'; +import { CacheScope, MetaTable } from '../../../utils/globals'; +import ProjectUser from '../../../models/ProjectUser'; import { validatePassword } from 'nocodb-sdk'; import boxen from 'boxen'; -import NocoCache from '../../cache/NocoCache'; -import { Tele } from 'nc-help'; +import NocoCache from '../../../cache/NocoCache'; +import { T } from 'nc-help'; const { isEmail } = require('validator'); const rolesLevel = { owner: 0, creator: 1, editor: 2, commenter: 3, viewer: 4 }; @@ -68,7 +68,7 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) { // if super admin not present if (await User.isFirst(ncMeta)) { // roles = 'owner,creator,editor' - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:invite', count: 1, }); @@ -126,7 +126,7 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) { ncMeta ); } else { - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:invite', count: 1, }); diff --git a/packages/nocodb/src/lib/controllers/userApi/userApis.ts b/packages/nocodb/src/lib/controllers/userApi/userApis.ts index b41ca7dfa1..fa35a5bd0d 100644 --- a/packages/nocodb/src/lib/controllers/userApi/userApis.ts +++ b/packages/nocodb/src/lib/controllers/userApi/userApis.ts @@ -1,30 +1,30 @@ import { Request, Response } from 'express'; import { TableType, validatePassword } from 'nocodb-sdk'; import { OrgUserRoles } from 'nocodb-sdk'; -import { NC_APP_SETTINGS } from '../../constants'; -import Store from '../../models/Store'; -import { Tele } from 'nc-help'; -import catchError, { NcError } from '../../meta/helpers/catchError'; +import { NC_APP_SETTINGS } from '../../../constants'; +import Store from '../../../models/Store'; +import { T } from 'nc-help'; +import catchError, { NcError } from '../../helpers/catchError'; const { isEmail } = require('validator'); import * as ejs from 'ejs'; import bcrypt from 'bcryptjs'; import { promisify } from 'util'; -import User from '../../models/User'; +import User from '../../../models/User'; const { v4: uuidv4 } = require('uuid'); -import Audit from '../../models/Audit'; -import NcPluginMgrv2 from '../../meta/helpers/NcPluginMgrv2'; +import Audit from '../../../models/Audit'; +import NcPluginMgrv2 from '../../helpers/NcPluginMgrv2'; import passport from 'passport'; -import extractProjectIdAndAuthenticate from '../../meta/helpers/extractProjectIdAndAuthenticate'; -import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; -import { MetaTable } from '../../utils/globals'; -import Noco from '../../Noco'; -import { getAjvValidatorMw } from '../../meta/api/helpers'; +import extractProjectIdAndAuthenticate from '../../helpers/extractProjectIdAndAuthenticate'; +import ncMetaAclMw from '../../helpers/ncMetaAclMw'; +import { MetaTable } from '../../../utils/globals'; +import Noco from '../../../Noco'; +import { getAjvValidatorMw } from '../helpers'; import { genJwt } from './helpers'; -import { randomTokenString } from '../../meta/helpers/stringHelpers'; +import { randomTokenString } from '../../helpers/stringHelpers'; export async function registerNewUserIfAllowed({ firstname, @@ -47,7 +47,7 @@ export async function registerNewUserIfAllowed({ roles = `${OrgUserRoles.CREATOR},${OrgUserRoles.SUPER_ADMIN}`; // todo: update in nc_store // roles = 'owner,creator,editor' - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:invite', count: 1, }); @@ -122,7 +122,7 @@ export async function signup(req: Request, res: Response) { const email_verification_token = uuidv4(); if (!ignore_subscribe) { - Tele.emit('evt_subscribe', email); + T.emit('evt_subscribe', email); } if (user) { diff --git a/packages/nocodb/src/lib/controllers/userController/index.ts b/packages/nocodb/src/lib/controllers/userController/index.ts index 0b42c7c9c3..70d17b40ef 100644 --- a/packages/nocodb/src/lib/controllers/userController/index.ts +++ b/packages/nocodb/src/lib/controllers/userController/index.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; import { TableType, validatePassword } from 'nocodb-sdk'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; const { isEmail } = require('validator'); import * as ejs from 'ejs'; @@ -64,7 +64,7 @@ export async function signup(req: Request, res: Response) { const email_verification_token = uuidv4(); if (!ignore_subscribe) { - Tele.emit('evt_subscribe', email); + T.emit('evt_subscribe', email); } if (user) { diff --git a/packages/nocodb/src/lib/controllers/viewController.ts b/packages/nocodb/src/lib/controllers/viewController.ts index e0a1cc6631..edbc2ed736 100644 --- a/packages/nocodb/src/lib/controllers/viewController.ts +++ b/packages/nocodb/src/lib/controllers/viewController.ts @@ -9,10 +9,7 @@ import { viewService } from '../services'; export async function viewGet(req: Request, res: Response) {} // @ts-ignore -export async function viewList( - req: Request, - res: Response -) { +export async function viewList(req: Request, res: Response) { const filteredViewList = await viewService.viewList({ tableId: req.params.tableId, user: (req as any).session?.passport?.user, diff --git a/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts index 9c47ab34ac..7643c92c9b 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts @@ -1,6 +1,6 @@ /* eslint-disable no-constant-condition */ import { knex, Knex } from 'knex'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import Debug from '../../util/Debug'; import Emit from '../../util/emit'; import Result from '../../util/Result'; @@ -620,7 +620,7 @@ class KnexClient extends SqlClient { KnexClient.___ext = await this._validateInput(); } if (!KnexClient.___ext) { - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:external', payload: null, check: true, diff --git a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts index 3f6a85b9c2..55ea1559d7 100644 --- a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts +++ b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts @@ -7,7 +7,7 @@ import fsExtra from 'fs-extra'; import importFresh from 'import-fresh'; import inflection from 'inflection'; import slash from 'slash'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import SqlClientFactory from '../sql-client/lib/SqlClientFactory'; // import debug from 'debug'; @@ -1047,7 +1047,7 @@ export default class SqlMgr { // t = process.hrtime(); const data = await require('axios')(...apiMeta); - Tele.emit('evt', { evt_type: 'import:excel:url' }); + T.emit('evt', { evt_type: 'import:excel:url' }); return data.data; } diff --git a/packages/nocodb/src/lib/meta/NcMetaMgr.ts b/packages/nocodb/src/lib/meta/NcMetaMgr.ts index aecaff7189..da98f2c5e9 100644 --- a/packages/nocodb/src/lib/meta/NcMetaMgr.ts +++ b/packages/nocodb/src/lib/meta/NcMetaMgr.ts @@ -40,7 +40,7 @@ import NcTemplateParser from '../v1-legacy/templates/NcTemplateParser'; import { defaultConnectionConfig } from '../utils/NcConfigFactory'; import xcMetaDiff from './handlers/xcMetaDiff'; import { UITypes } from 'nocodb-sdk'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { NC_ATTACHMENT_FIELD_SIZE } from '../constants'; const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 10); const XC_PLUGIN_DET = 'XC_PLUGIN_DET'; @@ -953,7 +953,7 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'webhooks:deleted' }); + T.emit('evt', { evt_type: 'webhooks:deleted' }); } catch (e) { throw e; } @@ -988,7 +988,7 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'webhooks:updated' }); + T.emit('evt', { evt_type: 'webhooks:updated' }); } else { const res = await this.xcMeta.metaInsert( projectId, @@ -1009,7 +1009,7 @@ export default class NcMetaMgr { description: `created webhook ${args.args.data.title} - ${args.args.data.event} ${args.args.data.operation} - ${args.args.data.notification?.type} - of table ${args.args.tn} `, ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'webhooks:created' }); + T.emit('evt', { evt_type: 'webhooks:created' }); return res; } @@ -1269,7 +1269,7 @@ export default class NcMetaMgr { } catch (e) { throw e; } finally { - Tele.emit('evt', { evt_type: 'image:uploaded' }); + T.emit('evt', { evt_type: 'image:uploaded' }); } } @@ -1595,7 +1595,7 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'project:created' }); + T.emit('evt', { evt_type: 'project:created' }); break; case 'projectUpdateByWeb': @@ -1603,7 +1603,7 @@ export default class NcMetaMgr { this.getProjectId(args), args.args.projectJson ); - Tele.emit('evt', { evt_type: 'project:updated' }); + T.emit('evt', { evt_type: 'project:updated' }); break; case 'projectCreateByOneClick': { @@ -1635,7 +1635,7 @@ export default class NcMetaMgr { description: `created project ${config.title}(${result.id}) `, ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'project:created', oneClick: true }); + T.emit('evt', { evt_type: 'project:created', oneClick: true }); } break; case 'projectCreateByWebWithXCDB': { @@ -1689,10 +1689,10 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'project:created', xcdb: true }); + T.emit('evt', { evt_type: 'project:created', xcdb: true }); postListenerCb = async () => { if (args?.args?.template) { - Tele.emit('evt', { + T.emit('evt', { evt_type: args.args?.quickImport ? 'project:created:fromExcel' : 'project:created:fromTemplate', @@ -1730,7 +1730,7 @@ export default class NcMetaMgr { case 'projectDelete': case 'projectRestart': case 'projectStart': - Tele.emit('evt', { evt_type: 'project:' + args.api }); + T.emit('evt', { evt_type: 'project:' + args.api }); result = null; break; @@ -2145,7 +2145,7 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'acl:updated' }); + T.emit('evt', { evt_type: 'acl:updated' }); return res; } catch (e) { @@ -3485,7 +3485,7 @@ export default class NcMetaMgr { ['id', 'view_id', 'view_type'] ); res.url = `${req.ncSiteUrl}${this.config.dashboardPath}#/nc/view/${res.view_id}`; - Tele.emit('evt', { evt_type: 'sharedView:generated-link' }); + T.emit('evt', { evt_type: 'sharedView:generated-link' }); return res; } catch (e) { console.log(e); @@ -3549,7 +3549,7 @@ export default class NcMetaMgr { sharedBase.url = `${req.ncSiteUrl}${this.config.dashboardPath}#/nc/base/${sharedBase.shared_base_id}`; - Tele.emit('evt', { evt_type: 'sharedBase:generated-link' }); + T.emit('evt', { evt_type: 'sharedBase:generated-link' }); return sharedBase; } catch (e) { console.log(e); @@ -3606,7 +3606,7 @@ export default class NcMetaMgr { // await this.xcMeta.metaUpdate(this.getProjectId(args), this.getDbAlias(args), 'nc_shared_views', { // password: args.args?.password // }, args.args.id); - // Tele.emit('evt', {evt_type: 'sharedView:password-updated'}) + // T.emit('evt', {evt_type: 'sharedView:password-updated'}) // return {msg: 'Success'}; // } catch (e) { // console.log(e) @@ -3623,7 +3623,7 @@ export default class NcMetaMgr { 'nc_shared_views', args.args.id ); - Tele.emit('evt', { evt_type: 'sharedView:deleted' }); + T.emit('evt', { evt_type: 'sharedView:deleted' }); return { msg: 'Success' }; } catch (e) { console.log(e); @@ -4477,7 +4477,7 @@ export default class NcMetaMgr { }); } - Tele.emit('evt', { evt_type: 'template:imported' }); + T.emit('evt', { evt_type: 'template:imported' }); return result; } @@ -5071,7 +5071,7 @@ export default class NcMetaMgr { } catch (e) { throw e; } finally { - Tele.emit('evt', { + T.emit('evt', { evt_type: 'plugin:installed', title: args.args.title, }); @@ -5153,7 +5153,7 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { + T.emit('evt', { evt_type: 'vtable:created', show_as: args.args.show_as, }); @@ -5270,7 +5270,7 @@ export default class NcMetaMgr { }); await RestAuthCtrl.instance.loadLatestApiTokens(); - Tele.emit('evt', { evt_type: 'apiToken:created' }); + T.emit('evt', { evt_type: 'apiToken:created' }); return { description: args.args.description, token, @@ -5282,7 +5282,7 @@ export default class NcMetaMgr { } protected async xcApiTokenDelete(args): Promise { - Tele.emit('evt', { evt_type: 'apiToken:deleted' }); + T.emit('evt', { evt_type: 'apiToken:deleted' }); const res = await this.xcMeta.metaDelete( null, null, @@ -5327,7 +5327,7 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { + T.emit('evt', { evt_type: 'vtable:renamed', show_as: args.args.show_as, }); @@ -5335,7 +5335,7 @@ export default class NcMetaMgr { } protected async xcVirtualTableUpdate(args): Promise { - // Tele.emit('evt', {evt_type: 'vtable:updated',show_as: args.args.show_as}) + // T.emit('evt', {evt_type: 'vtable:updated',show_as: args.args.show_as}) return this.xcMeta.metaUpdate( this.getProjectId(args), this.getDbAlias(args), @@ -5482,7 +5482,7 @@ export default class NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'vtable:deleted' }); + T.emit('evt', { evt_type: 'vtable:deleted' }); return res; } diff --git a/packages/nocodb/src/lib/meta/NcMetaMgrEE.ts b/packages/nocodb/src/lib/meta/NcMetaMgrEE.ts index dfa8dff104..c0e10ec8ab 100644 --- a/packages/nocodb/src/lib/meta/NcMetaMgrEE.ts +++ b/packages/nocodb/src/lib/meta/NcMetaMgrEE.ts @@ -1,5 +1,5 @@ import { v4 as uuidv4 } from 'uuid'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import NcMetaMgr from './NcMetaMgr'; @@ -104,7 +104,7 @@ export default class NcMetaMgrEE extends NcMetaMgr { ip: req.clientIp, }); - Tele.emit('evt', { evt_type: 'acl:updated' }); + T.emit('evt', { evt_type: 'acl:updated' }); return res; } catch (e) { @@ -277,7 +277,7 @@ export default class NcMetaMgrEE extends NcMetaMgr { sharedView.url = `${req.ncSiteUrl}${this.config.dashboardPath}#/nc/view/${sharedView.view_id}`; } - Tele.emit('evt', { evt_type: 'sharedView:generated-link' }); + T.emit('evt', { evt_type: 'sharedView:generated-link' }); return sharedView; } catch (e) { console.log(e); @@ -295,7 +295,7 @@ export default class NcMetaMgrEE extends NcMetaMgr { }, args.args.id ); - Tele.emit('evt', { evt_type: 'sharedView:password-updated' }); + T.emit('evt', { evt_type: 'sharedView:password-updated' }); return { msg: 'Success' }; } catch (e) { console.log(e); diff --git a/packages/nocodb/src/lib/meta/api/projectApis.ts b/packages/nocodb/src/lib/meta/api/projectApis.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/nocodb/src/lib/meta/helpers/apiMetrics.ts b/packages/nocodb/src/lib/meta/helpers/apiMetrics.ts index 82c6a0c32b..e276c99ef9 100644 --- a/packages/nocodb/src/lib/meta/helpers/apiMetrics.ts +++ b/packages/nocodb/src/lib/meta/helpers/apiMetrics.ts @@ -1,5 +1,5 @@ import { Request } from 'express'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; const countMap = {}; @@ -9,7 +9,7 @@ const metrics = async (req: Request, c = 150) => { const event = `a:api:${req.route.path}:${req.method}`; countMap[event] = (countMap[event] || 0) + 1; if (countMap[event] >= c) { - Tele.event({ event }); + T.event({ event }); countMap[event] = 0; } }; diff --git a/packages/nocodb/src/lib/models/GalleryView.ts b/packages/nocodb/src/lib/models/GalleryView.ts index 141e37cbcc..8f530d2154 100644 --- a/packages/nocodb/src/lib/models/GalleryView.ts +++ b/packages/nocodb/src/lib/models/GalleryView.ts @@ -1,6 +1,6 @@ import Noco from '../Noco'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; -import { BoolType, GalleryColumnType, GalleryType, UITypes } from 'nocodb-sdk' +import { BoolType, GalleryColumnType, GalleryType, UITypes } from 'nocodb-sdk'; import View from './View'; import NocoCache from '../cache/NocoCache'; import { extractProps } from '../meta/helpers/extractProps'; diff --git a/packages/nocodb/src/lib/models/Hook.ts b/packages/nocodb/src/lib/models/Hook.ts index 47a640d8d9..1761dc8c12 100644 --- a/packages/nocodb/src/lib/models/Hook.ts +++ b/packages/nocodb/src/lib/models/Hook.ts @@ -1,42 +1,42 @@ -import { BoolType, HookType } from 'nocodb-sdk' +import { BoolType, HookReqType, HookType } from 'nocodb-sdk' import { CacheDelDirection, CacheGetType, CacheScope, MetaTable, -} from '../utils/globals'; -import Noco from '../Noco'; -import Model from './Model'; -import NocoCache from '../cache/NocoCache'; -import Filter from './Filter'; -import HookFilter from './HookFilter'; -import { extractProps } from '../meta/helpers/extractProps'; +} from '../utils/globals' +import Noco from '../Noco' +import Model from './Model' +import NocoCache from '../cache/NocoCache' +import Filter from './Filter' +import HookFilter from './HookFilter' +import { extractProps } from '../meta/helpers/extractProps' export default class Hook implements HookType { - id?: string; - fk_model_id?: string; - title?: string; - description?: string; - env?: string; - type?: string; - event?: 'after' | 'before'; - operation?: 'insert' | 'delete' | 'update'; - async?: BoolType; - payload?: string; - url?: string; - headers?: string; - condition?: BoolType; - notification?: string; - retries?: number; - retry_interval?: number; - timeout?: number; - active?: BoolType; + id?: string + fk_model_id?: string + title?: string + description?: string + env?: string + type?: string + event?: 'after' | 'before' + operation?: 'insert' | 'delete' | 'update' + async?: BoolType + payload?: string + url?: string + headers?: string + condition?: BoolType + notification?: string + retries?: number + retry_interval?: number + timeout?: number + active?: BoolType - project_id?: string; - base_id?: string; + project_id?: string + base_id?: string - constructor(hook: Partial) { - Object.assign(this, hook); + constructor(hook: Partial) { + Object.assign(this, hook) } public static async get(hookId: string, ncMeta = Noco.ncMeta) { @@ -44,17 +44,17 @@ export default class Hook implements HookType { hookId && (await NocoCache.get( `${CacheScope.HOOK}:${hookId}`, - CacheGetType.TYPE_OBJECT - )); + CacheGetType.TYPE_OBJECT, + )) if (!hook) { - hook = await ncMeta.metaGet2(null, null, MetaTable.HOOKS, hookId); - await NocoCache.set(`${CacheScope.HOOK}:${hookId}`, hook); + hook = await ncMeta.metaGet2(null, null, MetaTable.HOOKS, hookId) + await NocoCache.set(`${CacheScope.HOOK}:${hookId}`, hook) } - return hook && new Hook(hook); + return hook && new Hook(hook) } public async getFilters(ncMeta = Noco.ncMeta) { - return await Filter.rootFilterListByHook({ hookId: this.id }, ncMeta); + return await Filter.rootFilterListByHook({ hookId: this.id }, ncMeta) } // public static async insert(hook: Partial) { @@ -81,9 +81,9 @@ export default class Hook implements HookType { event?: 'after' | 'before'; operation?: 'insert' | 'delete' | 'update'; }, - ncMeta = Noco.ncMeta + ncMeta = Noco.ncMeta, ) { - let hooks = await NocoCache.getList(CacheScope.HOOK, [param.fk_model_id]); + let hooks = await NocoCache.getList(CacheScope.HOOK, [param.fk_model_id]) if (!hooks.length) { hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, { condition: { @@ -96,31 +96,29 @@ export default class Hook implements HookType { orderBy: { created_at: 'asc', }, - }); - await NocoCache.setList(CacheScope.HOOK, [param.fk_model_id], hooks); + }) + await NocoCache.setList(CacheScope.HOOK, [param.fk_model_id], hooks) } // filter event & operation if (param.event) { hooks = hooks.filter( - (h) => h.event?.toLowerCase() === param.event?.toLowerCase() - ); + (h) => h.event?.toLowerCase() === param.event?.toLowerCase(), + ) } if (param.operation) { hooks = hooks.filter( - (h) => h.operation?.toLowerCase() === param.operation?.toLowerCase() - ); + (h) => h.operation?.toLowerCase() === param.operation?.toLowerCase(), + ) } - return hooks?.map((h) => new Hook(h)); + return hooks?.map((h) => new Hook(h)) } public static async insert( - hook: Partial< - Hook & { - created_at?; - updated_at?; - } - >, - ncMeta = Noco.ncMeta + hook: Partial, + ncMeta = Noco.ncMeta, ) { const insertObj = extractProps(hook, [ 'fk_model_id', @@ -142,49 +140,49 @@ export default class Hook implements HookType { 'base_id', 'created_at', 'updated_at', - ]); + ]) if (insertObj.event) { - insertObj.event = insertObj.event.toLowerCase() as 'after' | 'before'; + insertObj.event = insertObj.event.toLowerCase() as 'after' | 'before' } if (insertObj.operation) { insertObj.operation = insertObj.operation.toLowerCase() as | 'insert' | 'delete' - | 'update'; + | 'update' } if (insertObj.notification && typeof insertObj.notification === 'object') { - insertObj.notification = JSON.stringify(insertObj.notification); + insertObj.notification = JSON.stringify(insertObj.notification) } if (!(hook.project_id && hook.base_id)) { - const model = await Model.getByIdOrName({ id: hook.fk_model_id }, ncMeta); - insertObj.project_id = model.project_id; - insertObj.base_id = model.base_id; + const model = await Model.getByIdOrName({ id: hook.fk_model_id }, ncMeta) + insertObj.project_id = model.project_id + insertObj.base_id = model.base_id } const { id } = await ncMeta.metaInsert2( null, null, MetaTable.HOOKS, - insertObj - ); + insertObj, + ) await NocoCache.appendToList( CacheScope.HOOK, [hook.fk_model_id], - `${CacheScope.HOOK}:${id}` - ); + `${CacheScope.HOOK}:${id}`, + ) - return this.get(id, ncMeta); + return this.get(id, ncMeta) } public static async update( hookId: string, hook: Partial, - ncMeta = Noco.ncMeta + ncMeta = Noco.ncMeta, ) { const updateObj = extractProps(hook, [ 'title', @@ -203,38 +201,38 @@ export default class Hook implements HookType { 'retry_interval', 'timeout', 'active', - ]); + ]) if (updateObj.event) { - updateObj.event = updateObj.event.toLowerCase() as 'after' | 'before'; + updateObj.event = updateObj.event.toLowerCase() as 'after' | 'before' } if (updateObj.operation) { updateObj.operation = updateObj.operation.toLowerCase() as | 'insert' | 'delete' - | 'update'; + | 'update' } if (updateObj.notification && typeof updateObj.notification === 'object') { - updateObj.notification = JSON.stringify(updateObj.notification); + updateObj.notification = JSON.stringify(updateObj.notification) } // get existing cache - const key = `${CacheScope.HOOK}:${hookId}`; - let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); + const key = `${CacheScope.HOOK}:${hookId}` + let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) if (o) { // update data - o = { ...o, ...updateObj }; + o = { ...o, ...updateObj } // replace notification - o.notification = updateObj.notification; + o.notification = updateObj.notification // set cache - await NocoCache.set(key, o); + await NocoCache.set(key, o) } // set meta - await ncMeta.metaUpdate(null, null, MetaTable.HOOKS, updateObj, hookId); + await ncMeta.metaUpdate(null, null, MetaTable.HOOKS, updateObj, hookId) - return this.get(hookId, ncMeta); + return this.get(hookId, ncMeta) } static async delete(hookId: any, ncMeta = Noco.ncMeta) { @@ -245,22 +243,22 @@ export default class Hook implements HookType { MetaTable.FILTER_EXP, { condition: { fk_hook_id: hookId }, - } - ); + }, + ) for (const filter of filterList) { await NocoCache.deepDel( CacheScope.FILTER_EXP, `${CacheScope.FILTER_EXP}:${filter.id}`, - CacheDelDirection.CHILD_TO_PARENT - ); - await HookFilter.delete(filter.id); + CacheDelDirection.CHILD_TO_PARENT, + ) + await HookFilter.delete(filter.id) } // Delete Hook await NocoCache.deepDel( CacheScope.HOOK, `${CacheScope.HOOK}:${hookId}`, - CacheDelDirection.CHILD_TO_PARENT - ); - return await ncMeta.metaDelete(null, null, MetaTable.HOOKS, hookId); + CacheDelDirection.CHILD_TO_PARENT, + ) + return await ncMeta.metaDelete(null, null, MetaTable.HOOKS, hookId) } } diff --git a/packages/nocodb/src/lib/models/KanbanView.ts b/packages/nocodb/src/lib/models/KanbanView.ts index 6ac1b65d09..9bff3fbed4 100644 --- a/packages/nocodb/src/lib/models/KanbanView.ts +++ b/packages/nocodb/src/lib/models/KanbanView.ts @@ -1,5 +1,5 @@ import Noco from '../Noco'; -import { KanbanType, UITypes } from 'nocodb-sdk'; +import { BoolType, KanbanType, UITypes } from 'nocodb-sdk'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import View from './View'; import NocoCache from '../cache/NocoCache'; @@ -16,12 +16,12 @@ export default class KanbanView implements KanbanType { // below fields are not in use at this moment // keep them for time being - show?: boolean; + show?: BoolType; order?: number; uuid?: string; - public?: boolean; + public?: BoolType; password?: string; - show_all_fields?: boolean; + show_all_fields?: BoolType; constructor(data: KanbanView) { Object.assign(this, data); diff --git a/packages/nocodb/src/lib/models/Model.ts b/packages/nocodb/src/lib/models/Model.ts index eb32a3cc7b..4371c2841c 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -1,9 +1,9 @@ -import Noco from '../Noco' -import { parseMetaProp } from '../utils/modelUtils' -import Column from './Column' -import NocoCache from '../cache/NocoCache' -import { XKnex } from '../db/sql-data-mapper' -import { BaseModelSqlv2 } from '../db/sql-data-mapper/lib/sql/BaseModelSqlv2' +import Noco from '../Noco'; +import { parseMetaProp } from '../utils/modelUtils'; +import Column from './Column'; +import NocoCache from '../cache/NocoCache'; +import { XKnex } from '../db/sql-data-mapper'; +import { BaseModelSqlv2 } from '../db/sql-data-mapper/lib/sql/BaseModelSqlv2'; import { isVirtualCol, ModelTypes, @@ -12,52 +12,52 @@ import { TableType, UITypes, ViewTypes, -} from 'nocodb-sdk' +} from 'nocodb-sdk'; import { CacheDelDirection, CacheGetType, CacheScope, MetaTable, -} from '../utils/globals' -import View from './View' -import { NcError } from '../meta/helpers/catchError' -import Audit from './Audit' -import { sanitize } from '../db/sql-data-mapper/lib/sql/helpers/sanitize' -import { extractProps } from '../meta/helpers/extractProps' +} from '../utils/globals'; +import View from './View'; +import { NcError } from '../meta/helpers/catchError'; +import Audit from './Audit'; +import { sanitize } from '../db/sql-data-mapper/lib/sql/helpers/sanitize'; +import { extractProps } from '../meta/helpers/extractProps'; export default class Model implements TableType { - copy_enabled: BoolType - created_at: Date | number | string - base_id: 'db' | string - deleted: BoolType - enabled: BoolType - export_enabled: BoolType - id: string - order: number - parent_id: string - password: string - pin: BoolType - project_id: string - schema: any - show_all_fields: boolean - tags: string - type: ModelTypes - updated_at: Date | number | string - - table_name: string - title: string - - mm: BoolType - - uuid: string - - columns?: Column[] - columnsById?: { [id: string]: Column } - views?: View[] - meta?: Record | string + copy_enabled: BoolType; + created_at: Date | number | string; + base_id: 'db' | string; + deleted: BoolType; + enabled: BoolType; + export_enabled: BoolType; + id: string; + order: number; + parent_id: string; + password: string; + pin: BoolType; + project_id: string; + schema: any; + show_all_fields: boolean; + tags: string; + type: ModelTypes; + updated_at: Date | number | string; + + table_name: string; + title: string; + + mm: BoolType; + + uuid: string; + + columns?: Column[]; + columnsById?: { [id: string]: Column }; + views?: View[]; + meta?: Record | string; constructor(data: Partial) { - Object.assign(this, data) + Object.assign(this, data); } public async getColumns(ncMeta = Noco.ncMeta): Promise { @@ -65,34 +65,34 @@ export default class Model implements TableType { { fk_model_id: this.id, }, - ncMeta, - ) - return this.columns + ncMeta + ); + return this.columns; } // @ts-ignore public async getViews(force = false, ncMeta = Noco.ncMeta): Promise { - this.views = await View.listWithInfo(this.id, ncMeta) - return this.views + this.views = await View.listWithInfo(this.id, ncMeta); + return this.views; } public get primaryKey(): Column { - if (!this.columns) return null - return this.columns?.find((c) => c.pk) + if (!this.columns) return null; + return this.columns?.find((c) => c.pk); } public get primaryKeys(): Column[] { - if (!this.columns) return null - return this.columns?.filter((c) => c.pk) + if (!this.columns) return null; + return this.columns?.filter((c) => c.pk); } public get displayValue(): Column { - if (!this.columns) return null - const pCol = this.columns?.find((c) => c.pv) - if (pCol) return pCol - const pkIndex = this.columns.indexOf(this.primaryKey) - if (pkIndex < this.columns.length - 1) return this.columns[pkIndex + 1] - return this.columns[0] + if (!this.columns) return null; + const pCol = this.columns?.find((c) => c.pv); + if (pCol) return pCol; + const pkIndex = this.columns.indexOf(this.primaryKey); + if (pkIndex < this.columns.length - 1) return this.columns[pkIndex + 1]; + return this.columns[0]; } public static async insert( @@ -104,7 +104,7 @@ export default class Model implements TableType { updated_at?: any; type?: ModelTypes; }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { const insertObj = extractProps(model, [ 'table_name', @@ -115,9 +115,9 @@ export default class Model implements TableType { 'created_at', 'updated_at', 'id', - ]) + ]); - insertObj.mm = !!insertObj.mm + insertObj.mm = !!insertObj.mm; if (!insertObj.order) { insertObj.order = await ncMeta.metaGetNextOrder( @@ -125,26 +125,26 @@ export default class Model implements TableType { { project_id: projectId, base_id: baseId, - }, - ) + } + ); } if (!insertObj.type) { - insertObj.type = ModelTypes.TABLE + insertObj.type = ModelTypes.TABLE; } const { id } = await ncMeta.metaInsert2( projectId, baseId, MetaTable.MODELS, - insertObj, - ) + insertObj + ); await NocoCache.appendToList( CacheScope.MODEL, [projectId], - `${CacheScope.MODEL}:${id}`, - ) + `${CacheScope.MODEL}:${id}` + ); const view = await View.insert( { @@ -155,14 +155,14 @@ export default class Model implements TableType { created_at: model.created_at, updated_at: model.updated_at, }, - ncMeta, - ) + ncMeta + ); for (const column of model?.columns || []) { - await Column.insert({ ...column, fk_model_id: id, view } as any, ncMeta) + await Column.insert({ ...column, fk_model_id: id, view } as any, ncMeta); } - return this.getWithInfo({ id }, ncMeta) + return this.getWithInfo({ id }, ncMeta); } public static async list( @@ -173,13 +173,13 @@ export default class Model implements TableType { project_id: string; base_id: string; }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ): Promise { - let modelList = [] + let modelList = []; if (base_id) { - await NocoCache.getList(CacheScope.MODEL, [project_id, base_id]) + await NocoCache.getList(CacheScope.MODEL, [project_id, base_id]); } else { - await NocoCache.getList(CacheScope.MODEL, [project_id]) + await NocoCache.getList(CacheScope.MODEL, [project_id]); } if (!modelList.length) { modelList = await ncMeta.metaList2( @@ -190,30 +190,30 @@ export default class Model implements TableType { orderBy: { order: 'asc', }, - }, - ) + } + ); // parse meta of each model for (const model of modelList) { - model.meta = parseMetaProp(model) + model.meta = parseMetaProp(model); } if (base_id) { await NocoCache.setList( CacheScope.MODEL, [project_id, base_id], - modelList, - ) + modelList + ); } else { - await NocoCache.setList(CacheScope.MODEL, [project_id], modelList) + await NocoCache.setList(CacheScope.MODEL, [project_id], modelList); } } modelList.sort( (a, b) => (a.order != null ? a.order : Infinity) - - (b.order != null ? b.order : Infinity), - ) - return modelList.map((m) => new Model(m)) + (b.order != null ? b.order : Infinity) + ); + return modelList.map((m) => new Model(m)); } public static async listWithInfo( @@ -224,33 +224,33 @@ export default class Model implements TableType { project_id: string; db_alias: string; }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ): Promise { let modelList = await NocoCache.getList(CacheScope.MODEL, [ project_id, db_alias, - ]) + ]); if (!modelList.length) { modelList = await ncMeta.metaList2( project_id, db_alias, - MetaTable.MODELS, - ) + MetaTable.MODELS + ); // parse meta of each model for (const model of modelList) { - model.meta = parseMetaProp(model) + model.meta = parseMetaProp(model); } - await NocoCache.setList(CacheScope.MODEL, [project_id], modelList) + await NocoCache.setList(CacheScope.MODEL, [project_id], modelList); } - return modelList.map((m) => new Model(m)) + return modelList.map((m) => new Model(m)); } public static async clear({ id }: { id: string }): Promise { - await NocoCache.delAll(CacheScope.MODEL, `*${id}*`) - await Column.clearList({ fk_model_id: id }) + await NocoCache.delAll(CacheScope.MODEL, `*${id}*`); + await Column.clearList({ fk_model_id: id }); } public static async get(id: string, ncMeta = Noco.ncMeta): Promise { @@ -258,47 +258,47 @@ export default class Model implements TableType { id && (await NocoCache.get( `${CacheScope.MODEL}:${id}`, - CacheGetType.TYPE_OBJECT, - )) + CacheGetType.TYPE_OBJECT + )); if (!modelData) { - modelData = await ncMeta.metaGet2(null, null, MetaTable.MODELS, id) + modelData = await ncMeta.metaGet2(null, null, MetaTable.MODELS, id); if (modelData) { - modelData.meta = parseMetaProp(modelData) - await NocoCache.set(`${CacheScope.MODEL}:${modelData.id}`, modelData) + modelData.meta = parseMetaProp(modelData); + await NocoCache.set(`${CacheScope.MODEL}:${modelData.id}`, modelData); } } - return modelData && new Model(modelData) + return modelData && new Model(modelData); } public static async getByIdOrName( args: | { - project_id: string; - base_id: string; - table_name: string; - } + project_id: string; + base_id: string; + table_name: string; + } | { - id?: string; - }, - ncMeta = Noco.ncMeta, + id?: string; + }, + ncMeta = Noco.ncMeta ): Promise { - const k = 'id' in args ? args?.id : args + const k = 'id' in args ? args?.id : args; let modelData = k && (await NocoCache.get( `${CacheScope.MODEL}:${k}`, - CacheGetType.TYPE_OBJECT, - )) + CacheGetType.TYPE_OBJECT + )); if (!modelData) { - modelData = await ncMeta.metaGet2(null, null, MetaTable.MODELS, k) - modelData.meta = parseMetaProp(modelData) + modelData = await ncMeta.metaGet2(null, null, MetaTable.MODELS, k); + modelData.meta = parseMetaProp(modelData); } if (modelData) { - await NocoCache.set(`${CacheScope.MODEL}:${modelData.id}`, modelData) - return new Model(modelData) + await NocoCache.set(`${CacheScope.MODEL}:${modelData.id}`, modelData); + return new Model(modelData); } - return null + return null; } public static async getWithInfo( @@ -309,14 +309,14 @@ export default class Model implements TableType { table_name?: string; id?: string; }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ): Promise { let modelData = id && (await NocoCache.get( `${CacheScope.MODEL}:${id}`, - CacheGetType.TYPE_OBJECT, - )) + CacheGetType.TYPE_OBJECT + )); if (!modelData) { modelData = await ncMeta.metaGet2( null, @@ -324,23 +324,23 @@ export default class Model implements TableType { MetaTable.MODELS, id || { table_name, - }, - ) - modelData.meta = parseMetaProp(modelData) - await NocoCache.set(`${CacheScope.MODEL}:${modelData.id}`, modelData) + } + ); + modelData.meta = parseMetaProp(modelData); + await NocoCache.set(`${CacheScope.MODEL}:${modelData.id}`, modelData); // modelData.filters = await Filter.getFilterObject({ // viewId: modelData.id // }); // modelData.sorts = await Sort.list({ modelId: modelData.id }); } if (modelData) { - const m = new Model(modelData) - const columns = await m.getColumns(ncMeta) - await m.getViews(false, ncMeta) - m.columnsById = columns.reduce((agg, c) => ({ ...agg, [c.id]: c }), {}) - return m + const m = new Model(modelData); + const columns = await m.getColumns(ncMeta); + await m.getViews(false, ncMeta); + m.columnsById = columns.reduce((agg, c) => ({ ...agg, [c.id]: c }), {}); + return m; } - return null + return null; } public static async getBaseModelSQL( @@ -350,60 +350,60 @@ export default class Model implements TableType { dbDriver: XKnex; model?: Model; }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ): Promise { - const model = args?.model || (await this.get(args.id, ncMeta)) + const model = args?.model || (await this.get(args.id, ncMeta)); return new BaseModelSqlv2({ dbDriver: args.dbDriver, viewId: args.viewId, model, - }) + }); } async delete(ncMeta = Noco.ncMeta, force = false): Promise { - await Audit.deleteRowComments(this.id) + await Audit.deleteRowComments(this.id); for (const view of await this.getViews(true)) { - await view.delete() + await view.delete(); } for (const col of await this.getColumns(ncMeta)) { - let colOptionTableName = null - let cacheScopeName = null + let colOptionTableName = null; + let cacheScopeName = null; switch (col.uidt) { case UITypes.Rollup: - colOptionTableName = MetaTable.COL_ROLLUP - cacheScopeName = CacheScope.COL_ROLLUP - break + colOptionTableName = MetaTable.COL_ROLLUP; + cacheScopeName = CacheScope.COL_ROLLUP; + break; case UITypes.Lookup: - colOptionTableName = MetaTable.COL_LOOKUP - cacheScopeName = CacheScope.COL_LOOKUP - break + colOptionTableName = MetaTable.COL_LOOKUP; + cacheScopeName = CacheScope.COL_LOOKUP; + break; case UITypes.ForeignKey: case UITypes.LinkToAnotherRecord: - colOptionTableName = MetaTable.COL_RELATIONS - cacheScopeName = CacheScope.COL_RELATION - break + colOptionTableName = MetaTable.COL_RELATIONS; + cacheScopeName = CacheScope.COL_RELATION; + break; case UITypes.MultiSelect: case UITypes.SingleSelect: - colOptionTableName = MetaTable.COL_SELECT_OPTIONS - cacheScopeName = CacheScope.COL_SELECT_OPTION - break + colOptionTableName = MetaTable.COL_SELECT_OPTIONS; + cacheScopeName = CacheScope.COL_SELECT_OPTION; + break; case UITypes.Formula: - colOptionTableName = MetaTable.COL_FORMULA - cacheScopeName = CacheScope.COL_FORMULA - break + colOptionTableName = MetaTable.COL_FORMULA; + cacheScopeName = CacheScope.COL_FORMULA; + break; } if (colOptionTableName && cacheScopeName) { await ncMeta.metaDelete(null, null, colOptionTableName, { fk_column_id: col.id, - }) + }); await NocoCache.deepDel( cacheScopeName, `${cacheScopeName}:${col.id}`, - CacheDelDirection.CHILD_TO_PARENT, - ) + CacheDelDirection.CHILD_TO_PARENT + ); } } @@ -416,82 +416,82 @@ export default class Model implements TableType { condition: { fk_related_model_id: this.id, }, - }, - ) + } + ); for (const col of leftOverColumns) { await NocoCache.deepDel( CacheScope.COL_RELATION, `${CacheScope.COL_RELATION}:${col.fk_column_id}`, - CacheDelDirection.CHILD_TO_PARENT, - ) + CacheDelDirection.CHILD_TO_PARENT + ); } await ncMeta.metaDelete(null, null, MetaTable.COL_RELATIONS, { fk_related_model_id: this.id, - }) + }); } await NocoCache.deepDel( CacheScope.COLUMN, `${CacheScope.COLUMN}:${this.id}`, - CacheDelDirection.CHILD_TO_PARENT, - ) + CacheDelDirection.CHILD_TO_PARENT + ); await ncMeta.metaDelete(null, null, MetaTable.COLUMNS, { fk_model_id: this.id, - }) + }); await NocoCache.deepDel( CacheScope.MODEL, `${CacheScope.MODEL}:${this.id}`, - CacheDelDirection.CHILD_TO_PARENT, - ) - await ncMeta.metaDelete(null, null, MetaTable.MODELS, this.id) + CacheDelDirection.CHILD_TO_PARENT + ); + await ncMeta.metaDelete(null, null, MetaTable.MODELS, this.id); - await NocoCache.del(`${CacheScope.MODEL}:${this.project_id}:${this.id}`) - await NocoCache.del(`${CacheScope.MODEL}:${this.project_id}:${this.title}`) - return true + await NocoCache.del(`${CacheScope.MODEL}:${this.project_id}:${this.id}`); + await NocoCache.del(`${CacheScope.MODEL}:${this.project_id}:${this.title}`); + return true; } async mapAliasToColumn(data) { - const insertObj = {} + const insertObj = {}; for (const col of await this.getColumns()) { - if (isVirtualCol(col)) continue + if (isVirtualCol(col)) continue; let val = data?.[col.column_name] !== undefined ? data?.[col.column_name] - : data?.[col.title] + : data?.[col.title]; if (val !== undefined) { if (col.uidt === UITypes.Attachment && typeof val !== 'string') { - val = JSON.stringify(val) + val = JSON.stringify(val); } - insertObj[sanitize(col.column_name)] = val + insertObj[sanitize(col.column_name)] = val; } } - return insertObj + return insertObj; } static async updateAliasAndTableName( tableId, title: string, table_name: string, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { if (!title) { - NcError.badRequest('Missing \'title\' property in body') + NcError.badRequest("Missing 'title' property in body"); } if (!table_name) { - NcError.badRequest('Missing \'table_name\' property in body') + NcError.badRequest("Missing 'table_name' property in body"); } // get existing cache - const key = `${CacheScope.MODEL}:${tableId}` - const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) + const key = `${CacheScope.MODEL}:${tableId}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); // update alias if (o) { - o.title = title - o.table_name = table_name + o.title = title; + o.table_name = table_name; // set cache - await NocoCache.set(key, o) + await NocoCache.set(key, o); } // set meta return await ncMeta.metaUpdate( @@ -502,19 +502,19 @@ export default class Model implements TableType { title, table_name, }, - tableId, - ) + tableId + ); } static async markAsMmTable(tableId, isMm = true, ncMeta = Noco.ncMeta) { // get existing cache - const key = `${CacheScope.MODEL}:${tableId}` - const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) + const key = `${CacheScope.MODEL}:${tableId}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); // update alias if (o) { - o.mm = isMm + o.mm = isMm; // set cache - await NocoCache.set(key, o) + await NocoCache.set(key, o); } // set meta return await ncMeta.metaUpdate( @@ -524,40 +524,40 @@ export default class Model implements TableType { { mm: isMm, }, - tableId, - ) + tableId + ); } async getAliasColMapping() { return (await this.getColumns()).reduce((o, c) => { if (c.column_name) { - o[c.title] = c.column_name + o[c.title] = c.column_name; } - return o - }, {}) + return o; + }, {}); } async getColAliasMapping() { return (await this.getColumns()).reduce((o, c) => { if (c.column_name) { - o[c.column_name] = c.title + o[c.column_name] = c.title; } - return o - }, {}) + return o; + }, {}); } static async updateOrder( tableId: string, order: number, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { // get existing cache - const key = `${CacheScope.MODEL}:${tableId}` - const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) + const key = `${CacheScope.MODEL}:${tableId}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); if (o) { - o.order = order + o.order = order; // set cache - await NocoCache.set(key, o) + await NocoCache.set(key, o); } // set meta return await ncMeta.metaUpdate( @@ -567,29 +567,29 @@ export default class Model implements TableType { { order, }, - tableId, - ) + tableId + ); } static async updatePrimaryColumn( tableId: string, columnId: string, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { - const model = await this.getWithInfo({ id: tableId }) - const newPvCol = model.columns.find((c) => c.id === columnId) + const model = await this.getWithInfo({ id: tableId }); + const newPvCol = model.columns.find((c) => c.id === columnId); - if (!newPvCol) NcError.badRequest('Column not found') + if (!newPvCol) NcError.badRequest('Column not found'); // drop existing primary column/s for (const col of model.columns?.filter((c) => c.pv) || []) { // get existing cache - const key = `${CacheScope.COLUMN}:${col.id}` - const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) + const key = `${CacheScope.COLUMN}:${col.id}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); if (o) { - o.pv = false + o.pv = false; // set cache - await NocoCache.set(key, o) + await NocoCache.set(key, o); } // set meta await ncMeta.metaUpdate( @@ -599,17 +599,17 @@ export default class Model implements TableType { { pv: false, }, - col.id, - ) + col.id + ); } // get existing cache - const key = `${CacheScope.COLUMN}:${newPvCol.id}` - const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) + const key = `${CacheScope.COLUMN}:${newPvCol.id}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); if (o) { - o.pv = true + o.pv = true; // set cache - await NocoCache.set(key, o) + await NocoCache.set(key, o); } // set meta await ncMeta.metaUpdate( @@ -619,8 +619,8 @@ export default class Model implements TableType { { pv: true, }, - newPvCol.id, - ) + newPvCol.id + ); const grid_views_with_column = await ncMeta.metaList2( null, @@ -630,26 +630,26 @@ export default class Model implements TableType { condition: { fk_column_id: newPvCol.id, }, - }, - ) + } + ); if (grid_views_with_column.length) { for (const gv of grid_views_with_column) { - await View.fixPVColumnForView(gv.fk_view_id, ncMeta) + await View.fixPVColumnForView(gv.fk_view_id, ncMeta); } } - return true + return true; } static async setAsMm(id: any, ncMeta = Noco.ncMeta) { // get existing cache - const key = `${CacheScope.MODEL}:${id}` - const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) + const key = `${CacheScope.MODEL}:${id}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); if (o) { - o.mm = true + o.mm = true; // set cache - await NocoCache.set(key, o) + await NocoCache.set(key, o); } // set meta await ncMeta.metaUpdate( @@ -659,8 +659,8 @@ export default class Model implements TableType { { mm: true, }, - id, - ) + id + ); } static async getByAliasOrId( @@ -673,69 +673,69 @@ export default class Model implements TableType { base_id?: string; aliasOrId: string; }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { const modelId = project_id && aliasOrId && (await NocoCache.get( `${CacheScope.MODEL}:${project_id}:${aliasOrId}`, - CacheGetType.TYPE_OBJECT, - )) + CacheGetType.TYPE_OBJECT + )); if (!modelId) { const model = base_id ? await ncMeta.metaGet2( - null, - null, - MetaTable.MODELS, - { project_id, base_id }, - null, - { - _or: [ - { - id: { - eq: aliasOrId, + null, + null, + MetaTable.MODELS, + { project_id, base_id }, + null, + { + _or: [ + { + id: { + eq: aliasOrId, + }, }, - }, - { - title: { - eq: aliasOrId, + { + title: { + eq: aliasOrId, + }, }, - }, - ], - }, - ) + ], + } + ) : await ncMeta.metaGet2( - null, - null, - MetaTable.MODELS, - { project_id }, - null, - { - _or: [ - { - id: { - eq: aliasOrId, + null, + null, + MetaTable.MODELS, + { project_id }, + null, + { + _or: [ + { + id: { + eq: aliasOrId, + }, }, - }, - { - title: { - eq: aliasOrId, + { + title: { + eq: aliasOrId, + }, }, - }, - ], - }, - ) + ], + } + ); if (model) { await NocoCache.set( `${CacheScope.MODEL}:${project_id}:${aliasOrId}`, - model.id, - ) - await NocoCache.set(`${CacheScope.MODEL}:${model.id}`, model) + model.id + ); + await NocoCache.set(`${CacheScope.MODEL}:${model.id}`, model); } - return model && new Model(model) + return model && new Model(model); } - return modelId && this.get(modelId) + return modelId && this.get(modelId); } static async checkTitleAvailable( @@ -745,7 +745,7 @@ export default class Model implements TableType { base_id, exclude_id, }: { table_name; project_id; base_id; exclude_id? }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { return !(await ncMeta.metaGet2( project_id, @@ -755,8 +755,8 @@ export default class Model implements TableType { table_name, }, null, - exclude_id && { id: { neq: exclude_id } }, - )) + exclude_id && { id: { neq: exclude_id } } + )); } static async checkAliasAvailable( @@ -766,7 +766,7 @@ export default class Model implements TableType { base_id, exclude_id, }: { title; project_id; base_id; exclude_id? }, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { return !(await ncMeta.metaGet2( project_id, @@ -776,33 +776,32 @@ export default class Model implements TableType { title, }, null, - exclude_id && { id: { neq: exclude_id } }, - )) + exclude_id && { id: { neq: exclude_id } } + )); } async getAliasColObjMap() { return (await this.getColumns()).reduce( (sortAgg, c) => ({ ...sortAgg, [c.title]: c }), - {}, - ) + {} + ); } // For updating table meta static async updateMeta( tableId: string, meta: string | Record, - ncMeta = Noco.ncMeta, + ncMeta = Noco.ncMeta ) { // get existing cache - const key = `${CacheScope.MODEL}:${tableId}` - const existingCache = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) + const key = `${CacheScope.MODEL}:${tableId}`; + const existingCache = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); if (existingCache) { try { - existingCache.meta = typeof meta === 'string' ? JSON.parse(meta) : meta + existingCache.meta = typeof meta === 'string' ? JSON.parse(meta) : meta; // set cache - await NocoCache.set(key, existingCache) - } catch { - } + await NocoCache.set(key, existingCache); + } catch {} } // set meta return await ncMeta.metaUpdate( @@ -812,7 +811,7 @@ export default class Model implements TableType { { meta: typeof meta === 'object' ? JSON.stringify(meta) : meta, }, - tableId, - ) + tableId + ); } } diff --git a/packages/nocodb/src/lib/models/Project.ts b/packages/nocodb/src/lib/models/Project.ts index a3774b96d9..5ee799d1ab 100644 --- a/packages/nocodb/src/lib/models/Project.ts +++ b/packages/nocodb/src/lib/models/Project.ts @@ -1,6 +1,6 @@ import Base from './/Base'; import Noco from '../Noco'; -import { BoolType, MetaType, ProjectType } from 'nocodb-sdk' +import { BoolType, MetaType, ProjectType } from 'nocodb-sdk'; import { CacheDelDirection, CacheGetType, diff --git a/packages/nocodb/src/lib/services/apiTokenService.ts b/packages/nocodb/src/lib/services/apiTokenService.ts index aa106328f6..af94b7936b 100644 --- a/packages/nocodb/src/lib/services/apiTokenService.ts +++ b/packages/nocodb/src/lib/services/apiTokenService.ts @@ -1,5 +1,5 @@ import { ApiTokenReqType, OrgUserRoles } from 'nocodb-sdk'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { NcError } from '../meta/helpers/catchError'; import ApiToken from '../models/ApiToken'; import User from '../models/User'; @@ -11,7 +11,7 @@ export async function apiTokenCreate(param: { userId: string; tokenBody: ApiTokenReqType; }) { - Tele.emit('evt', { evt_type: 'apiToken:created' }); + T.emit('evt', { evt_type: 'apiToken:created' }); return ApiToken.insert({ ...param.tokenBody, fk_user_id: param.userId }); } @@ -23,7 +23,7 @@ export async function apiTokenDelete(param: { token; user: User }) { ) { NcError.notFound('Token not found'); } - Tele.emit('evt', { evt_type: 'apiToken:deleted' }); + T.emit('evt', { evt_type: 'apiToken:deleted' }); // todo: verify token belongs to the user return await ApiToken.delete(param.token); diff --git a/packages/nocodb/src/lib/services/attachmentService.ts b/packages/nocodb/src/lib/services/attachmentService.ts index 7b2b6d3169..f4a9bfdca1 100644 --- a/packages/nocodb/src/lib/services/attachmentService.ts +++ b/packages/nocodb/src/lib/services/attachmentService.ts @@ -4,7 +4,7 @@ import { nanoid } from 'nanoid'; import path from 'path'; import slash from 'slash'; import mimetypes, { mimeIcons } from '../utils/mimeTypes'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import NcPluginMgrv2 from '../meta/helpers/NcPluginMgrv2'; import Local from '../v1-legacy/plugins/adapters/storage/Local'; @@ -47,7 +47,7 @@ export async function upload(param: { }) ); - Tele.emit('evt', { evt_type: 'image:uploaded' }); + T.emit('evt', { evt_type: 'image:uploaded' }); return attachments; } @@ -97,7 +97,7 @@ export async function uploadViaURL(param: { }) ); - Tele.emit('evt', { evt_type: 'image:uploaded' }); + T.emit('evt', { evt_type: 'image:uploaded' }); return attachments; } diff --git a/packages/nocodb/src/lib/services/baseService.ts b/packages/nocodb/src/lib/services/baseService.ts index 1f390198c0..dbb5001bf0 100644 --- a/packages/nocodb/src/lib/services/baseService.ts +++ b/packages/nocodb/src/lib/services/baseService.ts @@ -2,7 +2,7 @@ import Project from '../models/Project'; import { BaseReqType } from 'nocodb-sdk'; import { syncBaseMigration } from '../meta/helpers/syncMigration'; import Base from '../models/Base'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { populateMeta } from '../meta/api/helpers'; export async function baseGetWithConfig(param: { baseId: any }) { @@ -29,7 +29,7 @@ export async function baseUpdate(param: { delete base.config; - Tele.emit('evt', { + T.emit('evt', { evt_type: 'base:updated', }); @@ -45,7 +45,7 @@ export async function baseList(param: { projectId: string }) { export async function baseDelete(param: { baseId: string }) { const base = await Base.get(param.baseId); await base.delete(); - Tele.emit('evt', { evt_type: 'base:deleted' }); + T.emit('evt', { evt_type: 'base:deleted' }); return true; } @@ -66,11 +66,11 @@ export async function baseCreate(param: { const info = await populateMeta(base, project); - Tele.emit('evt_api_created', info); + T.emit('evt_api_created', info); delete base.config; - Tele.emit('evt', { + T.emit('evt', { evt_type: 'base:created', }); diff --git a/packages/nocodb/src/lib/services/cacheService.ts b/packages/nocodb/src/lib/services/cacheService.ts index 6e3b83df86..968da7c33f 100644 --- a/packages/nocodb/src/lib/services/cacheService.ts +++ b/packages/nocodb/src/lib/services/cacheService.ts @@ -1,10 +1,10 @@ import NocoCache from '../cache/NocoCache'; export async function cacheGet() { - return await NocoCache.export(); + return await NocoCache.export(); } export async function cacheDelete() { - await NocoCache.destroy() - return true + await NocoCache.destroy(); + return true; } diff --git a/packages/nocodb/src/lib/services/columnService.ts b/packages/nocodb/src/lib/services/columnService.ts index c8c1f80f4e..f2c741f546 100644 --- a/packages/nocodb/src/lib/services/columnService.ts +++ b/packages/nocodb/src/lib/services/columnService.ts @@ -6,20 +6,21 @@ import { LinkToAnotherColumnReqType, LinkToAnotherRecordType, RelationTypes, - substituteColumnAliasWithIdInFormula, substituteColumnIdWithAliasInFormula, + substituteColumnAliasWithIdInFormula, + substituteColumnIdWithAliasInFormula, UITypes, -} from 'nocodb-sdk' +} from 'nocodb-sdk'; import formulaQueryBuilderv2 from '../db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2'; import ProjectMgrv2 from '../db/sql-mgr/v2/ProjectMgrv2'; import SqlMgrv2 from '../db/sql-mgr/v2/SqlMgrv2'; -import { Altered } from '../meta/api/columnApis'; import { createHmAndBtColumn, generateFkName, randomID, - validateLookupPayload, validateRequiredField, + validateLookupPayload, + validateRequiredField, validateRollupPayload, -} from '../meta/api/helpers' +} from '../meta/api/helpers'; import { NcError } from '../meta/helpers/catchError'; import getColumnPropsFromUIDT from '../meta/helpers/getColumnPropsFromUIDT'; import { @@ -32,7 +33,7 @@ import NcMetaIO from '../meta/NcMetaIO'; import Audit from '../models/Audit'; import Base from '../models/Base'; import Column from '../models/Column'; -import FormulaColumn from '../models/FormulaColumn' +import FormulaColumn from '../models/FormulaColumn'; import KanbanView from '../models/KanbanView'; import LinkToAnotherRecordColumn from '../models/LinkToAnotherRecordColumn'; import Model from '../models/Model'; @@ -40,14 +41,21 @@ import Project from '../models/Project'; import Noco from '../Noco'; import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2'; -import { Tele } from 'nc-help'; -import { MetaTable } from '../utils/globals' +import { T } from 'nc-help'; +import { MetaTable } from '../utils/globals'; + +export enum Altered { + NEW_COLUMN = 1, + DELETE_COLUMN = 4, + UPDATE_COLUMN = 8, +} export async function columnUpdate(param: { columnId: string; - column: ColumnReqType & {colOptions?: any}, - cookie?: any, + column: ColumnReqType & { colOptions?: any }; + cookie?: any; }) { + const { cookie } = param; const column = await Column.get({ colId: param.columnId }); const table = await Model.getWithInfo({ @@ -88,7 +96,10 @@ export async function columnUpdate(param: { NcError.badRequest('Duplicate column alias'); } - let colBody = { ...param.column } as Column & { formula?: string; formula_raw?: string }; + let colBody = { ...param.column } as Column & { + formula?: string; + formula_raw?: string; + }; if ( [ UITypes.Lookup, @@ -606,7 +617,7 @@ export async function columnUpdate(param: { await baseModel.bulkUpdateAll( { where: `(${column.title},eq,${ch.temp_title})` }, { [column.column_name]: newOp.title }, - { cookie: req } + { cookie } ); } } else if (column.uidt === UITypes.MultiSelect) { @@ -806,9 +817,9 @@ export async function columnUpdate(param: { }).then(() => {}); await table.getColumns(); - Tele.emit('evt', { evt_type: 'column:updated' }); + T.emit('evt', { evt_type: 'column:updated' }); - return table + return table; } export async function columnGet(param: { columnId: string }) { @@ -893,7 +904,7 @@ export async function columnAdd(param: { case UITypes.LinkToAnotherRecord: await createLTARColumn({ ...param, base, project }); - Tele.emit('evt', { evt_type: 'relation:created' }); + T.emit('evt', { evt_type: 'relation:created' }); break; case UITypes.QrCode: @@ -1098,10 +1109,9 @@ export async function columnAdd(param: { // ip: (req as any).clientIp, }).then(() => {}); - Tele.emit('evt', { evt_type: 'column:created' }); - - return table + T.emit('evt', { evt_type: 'column:created' }); + return table; } export async function columnDelete(param: { columnId: string }) { @@ -1255,7 +1265,7 @@ export async function columnDelete(param: { columnId: string }) { break; } } - Tele.emit('evt', { evt_type: 'raltion:deleted' }); + T.emit('evt', { evt_type: 'raltion:deleted' }); break; case UITypes.ForeignKey: { NcError.notImplemented(); @@ -1321,7 +1331,7 @@ export async function columnDelete(param: { columnId: string }) { ); } - Tele.emit('evt', { evt_type: 'column:deleted' }); + T.emit('evt', { evt_type: 'column:deleted' }); return table; } diff --git a/packages/nocodb/src/lib/services/dataService/export.ts b/packages/nocodb/src/lib/services/dataService/export.ts index 2ebc209262..f74e5299f9 100644 --- a/packages/nocodb/src/lib/services/dataService/export.ts +++ b/packages/nocodb/src/lib/services/dataService/export.ts @@ -1,25 +1,35 @@ import { Request, Response, Router } from 'express'; -import { isSystemColumn } from 'nocodb-sdk' +import { isSystemColumn } from 'nocodb-sdk'; import * as XLSX from 'xlsx'; -import getAst from '../../db/sql-data-mapper/lib/sql/helpers/getAst' +import getAst from '../../db/sql-data-mapper/lib/sql/helpers/getAst'; import ncMetaAclMw from '../../helpers/ncMetaAclMw'; -import { extractXlsxData, serializeCellValue } from '../../meta/api/dataApis/helpers' import { - extractCsvData, getViewAndModelByAliasOrId, - getViewAndModelFromRequestByAliasOrId, PathParams, -} from './helpers' + extractXlsxData, + serializeCellValue, +} from '../../meta/api/dataApis/helpers'; +import { + extractCsvData, + getViewAndModelByAliasOrId, + getViewAndModelFromRequestByAliasOrId, + PathParams, +} from './helpers'; import apiMetrics from '../../helpers/apiMetrics'; import View from '../../../models/View'; -async function excelDataExport(param:PathParams&{ - query: any; -}) { +async function excelDataExport( + param: PathParams & { + query: any; + } +) { const { model, view } = await getViewAndModelByAliasOrId(param); let targetView = view; if (!targetView) { targetView = await View.getDefaultView(model.id); } - const { offset, elapsed, data } = await extractXlsxData({view: targetView, query:req.query }); + const { offset, elapsed, data } = await extractXlsxData({ + view: targetView, + query: req.query, + }); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, data, targetView.title); const buf = XLSX.write(wb, { type: 'base64', bookType: 'xlsx' }); diff --git a/packages/nocodb/src/lib/services/dataService/helpers.ts b/packages/nocodb/src/lib/services/dataService/helpers.ts index 02c56c7a39..9654fc3dfc 100644 --- a/packages/nocodb/src/lib/services/dataService/helpers.ts +++ b/packages/nocodb/src/lib/services/dataService/helpers.ts @@ -1,18 +1,18 @@ -import { Request } from 'express' -import { nocoExecute } from 'nc-help' -import { isSystemColumn, UITypes } from 'nocodb-sdk' -import * as XLSX from 'xlsx' -import { BaseModelSqlv2 } from '../../db/sql-data-mapper/lib/sql/BaseModelSqlv2' -import getAst from '../../db/sql-data-mapper/lib/sql/helpers/getAst' -import { NcError } from '../../meta/helpers/catchError' -import { Model, View } from '../../models' -import Base from '../../models/Base' -import Column from '../../models/Column' -import LinkToAnotherRecordColumn from '../../models/LinkToAnotherRecordColumn' -import LookupColumn from '../../models/LookupColumn' -import Project from '../../models/Project' -import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2' - +import { Request } from 'express'; +import { nocoExecute } from 'nc-help'; +import { isSystemColumn, UITypes } from 'nocodb-sdk'; +import * as XLSX from 'xlsx'; +import { BaseModelSqlv2 } from '../../db/sql-data-mapper/lib/sql/BaseModelSqlv2'; +import getAst from '../../db/sql-data-mapper/lib/sql/helpers/getAst'; +import { NcError } from '../../meta/helpers/catchError'; +import { Model, View } from '../../models'; +import Base from '../../models/Base'; +import Column from '../../models/Column'; +import LinkToAnotherRecordColumn from '../../models/LinkToAnotherRecordColumn'; +import LookupColumn from '../../models/LookupColumn'; +import Project from '../../models/Project'; +import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2'; +import papaparse from 'papaparse'; export interface PathParams { projectName: string; @@ -41,8 +41,6 @@ export async function getViewAndModelByAliasOrId(param: { return { model, view }; } - - export async function extractXlsxData(view: View, req: Request) { const base = await Base.get(view.base_id); @@ -63,7 +61,12 @@ export async function extractXlsxData(view: View, req: Request) { dbDriver: NcConnectionMgrv2.get(base), }); - const { offset, dbRows, elapsed } = await getDbRows(baseModel, view, req); + const { offset, dbRows, elapsed } = await getDbRows({ + baseModel, + view, + siteUrl: (req as any).ncSiteUrl, + query: req.query, + }); const fields = req.query.fields as string[]; @@ -93,7 +96,12 @@ export async function extractCsvData(view: View, req: Request) { dbDriver: NcConnectionMgrv2.get(base), }); - const { offset, dbRows, elapsed } = await getDbRows(baseModel, view, req); + const { offset, dbRows, elapsed } = await getDbRows({ + baseModel, + view, + query: req.query, + siteUrl: (req as any).ncSiteUrl, + }); const data = papaparse.unparse( { @@ -118,70 +126,11 @@ export async function extractCsvData(view: View, req: Request) { return { offset, dbRows, elapsed, data }; } - -async function getDbRows(baseModel, view: View, req: Request) { - let offset = +req.query.offset || 0; - const limit = 100; - // const size = +process.env.NC_EXPORT_MAX_SIZE || 1024; - const timeout = +process.env.NC_EXPORT_MAX_TIMEOUT || 5000; - const dbRows = []; - const startTime = process.hrtime(); - let elapsed, temp; - - const listArgs: any = { ...req.query }; - try { - listArgs.filterArr = JSON.parse(listArgs.filterArrJson); - } catch (e) {} - try { - listArgs.sortArr = JSON.parse(listArgs.sortArrJson); - } catch (e) {} - - for ( - elapsed = 0; - elapsed < timeout; - offset += limit, - temp = process.hrtime(startTime), - elapsed = temp[0] * 1000 + temp[1] / 1000000 - ) { - const rows = await nocoExecute( - await getAst({ - query: req.query, - includePkByDefault: false, - model: view.model, - view, - }), - await baseModel.list({ ...listArgs, offset, limit }), - {}, - req.query - ); - - if (!rows?.length) { - offset = -1; - break; - } - - for (const row of rows) { - const dbRow = { ...row }; - - for (const column of view.model.columns) { - if (isSystemColumn(column) && !view.show_system_fields) continue; - dbRow[column.title] = await serializeCellValue({ - value: row[column.title], - column, - siteUrl: req['ncSiteUrl'], - }); - } - dbRows.push(dbRow); - } - } - return { offset, dbRows, elapsed }; -} - export async function serializeCellValue({ - value, - column, - siteUrl, - }: { + value, + column, + siteUrl, +}: { column?: Column; value: any; siteUrl: string; @@ -209,34 +158,34 @@ export async function serializeCellValue({ ); } case UITypes.Lookup: - { - const colOptions = await column.getColOptions(); - const lookupColumn = await colOptions.getLookupColumn(); - return ( - await Promise.all( - [...(Array.isArray(value) ? value : [value])].map(async (v) => - serializeCellValue({ - value: v, - column: lookupColumn, - siteUrl, - }) + { + const colOptions = await column.getColOptions(); + const lookupColumn = await colOptions.getLookupColumn(); + return ( + await Promise.all( + [...(Array.isArray(value) ? value : [value])].map(async (v) => + serializeCellValue({ + value: v, + column: lookupColumn, + siteUrl, + }) + ) ) - ) - ).join(', '); - } + ).join(', '); + } break; case UITypes.LinkToAnotherRecord: - { - const colOptions = - await column.getColOptions(); - const relatedModel = await colOptions.getRelatedTable(); - await relatedModel.getColumns(); - return [...(Array.isArray(value) ? value : [value])] - .map((v) => { - return v[relatedModel.displayValue?.title]; - }) - .join(', '); - } + { + const colOptions = + await column.getColOptions(); + const relatedModel = await colOptions.getRelatedTable(); + await relatedModel.getColumns(); + return [...(Array.isArray(value) ? value : [value])] + .map((v) => { + return v[relatedModel.displayValue?.title]; + }) + .join(', '); + } break; default: if (value && typeof value === 'object') { @@ -263,9 +212,12 @@ export async function getColumnByIdOrName( return column; } - - -async function getDbRows(param: { baseModel:BaseModelSqlv2, view: View, query: any; siteUrl: string; }) { +export async function getDbRows(param: { + baseModel: BaseModelSqlv2; + view: View; + query: any; + siteUrl: string; +}) { const { baseModel, view, query = {}, siteUrl } = param; let offset = +query.offset || 0; const limit = 100; diff --git a/packages/nocodb/src/lib/services/dataService/index.ts b/packages/nocodb/src/lib/services/dataService/index.ts index 668da2a598..44e4b7bedb 100644 --- a/packages/nocodb/src/lib/services/dataService/index.ts +++ b/packages/nocodb/src/lib/services/dataService/index.ts @@ -4,7 +4,7 @@ import { NcError } from '../../meta/helpers/catchError'; import { PagedResponseImpl } from '../../meta/helpers/PagedResponse'; import { Base, Model, View } from '../../models'; import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2'; -import { getViewAndModelByAliasOrId, PathParams } from './helpers' +import { getViewAndModelByAliasOrId, PathParams } from './helpers'; export async function dataList(param: PathParams & { query: any }) { const { model, view } = await getViewAndModelByAliasOrId(param); @@ -322,7 +322,6 @@ export async function getGroupedDataList(param: { return data; } - export async function dataListByViewId(param: { viewId: string; query: any }) { const view = await View.get(param.viewId); @@ -795,3 +794,5 @@ export async function relationDataAdd(param: { return true; } + +export * from './helpers' diff --git a/packages/nocodb/src/lib/services/filterService.ts b/packages/nocodb/src/lib/services/filterService.ts index 8b40b4b813..c52089118b 100644 --- a/packages/nocodb/src/lib/services/filterService.ts +++ b/packages/nocodb/src/lib/services/filterService.ts @@ -1,68 +1,67 @@ -import { FilterReqType } from 'nocodb-sdk' -import Filter from '../models/Filter' -import { Tele } from 'nc-help'; +import { FilterReqType } from 'nocodb-sdk'; +import Filter from '../models/Filter'; +import { T } from 'nc-help'; -export async function hookFilterCreate(param: { filter: FilterReqType; hookId: any }) { +export async function hookFilterCreate(param: { + filter: FilterReqType; + hookId: any; +}) { const filter = await Filter.insert({ ...param.filter, fk_hook_id: param.hookId, - }) + }); - Tele.emit('evt', { evt_type: 'hookFilter:created' }) - return filter + T.emit('evt', { evt_type: 'hookFilter:created' }); + return filter; } - export async function hookFilterList(param: { hookId: any }) { - return Filter.rootFilterListByHook({ hookId: param.hookId }) + return Filter.rootFilterListByHook({ hookId: param.hookId }); } export async function filterDelete(param: { filterId: string }) { - await Filter.delete(param.filterId) - Tele.emit('evt', { evt_type: 'filter:deleted' }) + await Filter.delete(param.filterId); + T.emit('evt', { evt_type: 'filter:deleted' }); return true; } - export async function filterCreate(param: { - filter: FilterReqType - viewId: string + filter: FilterReqType; + viewId: string; }) { const filter = await Filter.insert({ ...param.filter, fk_view_id: param.viewId, }); - Tele.emit('evt', { evt_type: 'filter:created' }); + T.emit('evt', { evt_type: 'filter:created' }); - return filter + return filter; } export async function filterUpdate(param: { - filter: FilterReqType - filterId: string + filter: FilterReqType; + filterId: string; }) { - const filter = await Filter.update(param.filterId, param.filter) + // todo: type correction + const filter = await Filter.update(param.filterId, param.filter as Filter); + T.emit('evt', { evt_type: 'filter:updated' }); - Tele.emit('evt', { evt_type: 'filter:updated' }) - - return filter + return filter; } - export async function filterChildrenList(param: { filterId: any }) { return Filter.parentFilterList({ parentId: param.filterId, - }) + }); } - export async function filterGet(param: { filterId: string }) { - const filter = await Filter.get(param.filterId) - return filter + const filter = await Filter.get(param.filterId); + return filter; } export async function filterList(param: { viewId: string }) { - const filter = await Filter.rootFilterList({ viewId: param.viewId }) - return filter + const filter = await Filter.rootFilterList({ viewId: param.viewId }); + return filter; } diff --git a/packages/nocodb/src/lib/services/formViewColumnService.ts b/packages/nocodb/src/lib/services/formViewColumnService.ts index afef0e02f3..b91d171f3b 100644 --- a/packages/nocodb/src/lib/services/formViewColumnService.ts +++ b/packages/nocodb/src/lib/services/formViewColumnService.ts @@ -1,11 +1,11 @@ import { FormViewColumn } from '../models'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; export async function columnUpdate(param: { formViewColumnId: string; // todo: replace with FormColumnReq formViewColumn: FormViewColumn; }) { - Tele.emit('evt', { evt_type: 'formViewColumn:updated' }); + T.emit('evt', { evt_type: 'formViewColumn:updated' }); return await FormViewColumn.update( param.formViewColumnId, param.formViewColumn diff --git a/packages/nocodb/src/lib/services/formViewService.ts b/packages/nocodb/src/lib/services/formViewService.ts index d9a4667c72..eec4c66624 100644 --- a/packages/nocodb/src/lib/services/formViewService.ts +++ b/packages/nocodb/src/lib/services/formViewService.ts @@ -1,4 +1,4 @@ -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { FormReqType, ViewTypes } from 'nocodb-sdk'; import { FormView, View } from '../models'; @@ -11,7 +11,7 @@ export async function formViewCreate(param: { tableId: string; body: FormReqType; }) { - Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'form' }); + T.emit('evt', { evt_type: 'vtable:created', show_as: 'form' }); const view = await View.insert({ ...param.body, // todo: sanitize @@ -26,6 +26,6 @@ export async function formViewUpdate(param: { formViewId: string; body: FormReqType; }) { - Tele.emit('evt', { evt_type: 'view:updated', type: 'grid' }); + T.emit('evt', { evt_type: 'view:updated', type: 'grid' }); await FormView.update(param.formViewId, param.body); } diff --git a/packages/nocodb/src/lib/services/galleryViewService.ts b/packages/nocodb/src/lib/services/galleryViewService.ts index 9132202b74..9e8ab05d5d 100644 --- a/packages/nocodb/src/lib/services/galleryViewService.ts +++ b/packages/nocodb/src/lib/services/galleryViewService.ts @@ -1,6 +1,6 @@ import { GalleryReqType, ViewTypes } from 'nocodb-sdk'; -import { Tele } from 'nc-help'; -import { GalleryView, View } from '../models' +import { T } from 'nc-help'; +import { GalleryView, View } from '../models'; export async function galleryViewGet(param: { galleryViewId: string }) { return await GalleryView.get(param.galleryViewId); @@ -10,7 +10,7 @@ export async function galleryViewCreate(param: { tableId: string; gallery: GalleryReqType; }) { - Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'gallery' }); + T.emit('evt', { evt_type: 'vtable:created', show_as: 'gallery' }); const view = await View.insert({ ...param.gallery, // todo: sanitize @@ -24,6 +24,6 @@ export async function galleryViewUpdate(param: { galleryViewId: string; gallery: GalleryReqType; }) { - Tele.emit('evt', { evt_type: 'view:updated', type: 'gallery' }); + T.emit('evt', { evt_type: 'view:updated', type: 'gallery' }); await GalleryView.update(param.galleryViewId, param.gallery); } diff --git a/packages/nocodb/src/lib/services/gridViewColumnService.ts b/packages/nocodb/src/lib/services/gridViewColumnService.ts index 06731ec3b1..e24dd07177 100644 --- a/packages/nocodb/src/lib/services/gridViewColumnService.ts +++ b/packages/nocodb/src/lib/services/gridViewColumnService.ts @@ -1,6 +1,6 @@ import { GridColumnReqType } from 'nocodb-sdk'; import GridViewColumn from '../models/GridViewColumn'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; export async function columnList(param: { gridViewId: string }) { return await GridViewColumn.list(param.gridViewId); @@ -10,6 +10,6 @@ export async function gridColumnUpdate(param: { gridViewColumnId: string; grid: GridColumnReqType; }) { - Tele.emit('evt', { evt_type: 'gridViewColumn:updated' }); + T.emit('evt', { evt_type: 'gridViewColumn:updated' }); return await GridViewColumn.update(param.gridViewColumnId, param.grid); } diff --git a/packages/nocodb/src/lib/services/gridViewService.ts b/packages/nocodb/src/lib/services/gridViewService.ts index 55315d1fc8..c99f63552e 100644 --- a/packages/nocodb/src/lib/services/gridViewService.ts +++ b/packages/nocodb/src/lib/services/gridViewService.ts @@ -1,4 +1,4 @@ -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { GridReqType, ViewTypes } from 'nocodb-sdk'; import { View } from '../models'; import { GridView } from '../models'; @@ -13,7 +13,7 @@ export async function gridViewCreate(param: { fk_model_id: param.tableId, type: ViewTypes.GRID, }); - Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'grid' }); + T.emit('evt', { evt_type: 'vtable:created', show_as: 'grid' }); return view; } @@ -21,6 +21,6 @@ export async function gridViewUpdate(param: { viewId: string; grid: GridReqType; }) { - Tele.emit('evt', { evt_type: 'view:updated', type: 'grid' }); + T.emit('evt', { evt_type: 'view:updated', type: 'grid' }); return await GridView.update(param.viewId, param.grid); } diff --git a/packages/nocodb/src/lib/services/hookFilterService.ts b/packages/nocodb/src/lib/services/hookFilterService.ts index e8e94d7233..d4c0b2636d 100644 --- a/packages/nocodb/src/lib/services/hookFilterService.ts +++ b/packages/nocodb/src/lib/services/hookFilterService.ts @@ -1,4 +1,4 @@ -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { FilterReqType } from 'nocodb-sdk'; import Filter from '../models/Filter'; @@ -37,7 +37,7 @@ export async function filterCreate(param: { fk_hook_id: param.hookId, }); - Tele.emit('evt', { evt_type: 'hookFilter:created' }); + T.emit('evt', { evt_type: 'hookFilter:created' }); return filter; } @@ -50,12 +50,12 @@ export async function filterUpdate(param: { ...param.filter, fk_hook_id: param.hookId, } as Filter); - Tele.emit('evt', { evt_type: 'hookFilter:updated' }); + T.emit('evt', { evt_type: 'hookFilter:updated' }); return filter; } export async function filterDelete(param: { filterId: string }) { await Filter.delete(param.filterId); - Tele.emit('evt', { evt_type: 'hookFilter:deleted' }); + T.emit('evt', { evt_type: 'hookFilter:deleted' }); return true; } diff --git a/packages/nocodb/src/lib/services/hookService.ts b/packages/nocodb/src/lib/services/hookService.ts index 17cef05229..2e20732c17 100644 --- a/packages/nocodb/src/lib/services/hookService.ts +++ b/packages/nocodb/src/lib/services/hookService.ts @@ -1,4 +1,4 @@ -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { Hook, Model } from '../models'; import { HookReqType, HookTestReqType } from 'nocodb-sdk'; @@ -14,24 +14,26 @@ export async function hookCreate(param: { tableId: string; hook: HookReqType; }) { - Tele.emit('evt', { evt_type: 'webhooks:created' }); + T.emit('evt', { evt_type: 'webhooks:created' }); + // todo: type correction const hook = await Hook.insert({ ...param.hook, fk_model_id: param.tableId, - }); + } as any); return hook; } export async function hookDelete(param: { hookId: string }) { - Tele.emit('evt', { evt_type: 'webhooks:deleted' }); + T.emit('evt', { evt_type: 'webhooks:deleted' }); await Hook.delete(param.hookId); return true; } export async function hookUpdate(param: { hookId: string; hook: HookReqType }) { - Tele.emit('evt', { evt_type: 'webhooks:updated' }); + T.emit('evt', { evt_type: 'webhooks:updated' }); - return await Hook.update(param.hookId, param.hook); + // todo: correction in swagger + return await Hook.update(param.hookId, param.hook as any); } export async function hookTest(param: { @@ -53,7 +55,7 @@ export async function hookTest(param: { true ); - Tele.emit('evt', { evt_type: 'webhooks:tested' }); + T.emit('evt', { evt_type: 'webhooks:tested' }); return true; } diff --git a/packages/nocodb/src/lib/services/kanbanViewService.ts b/packages/nocodb/src/lib/services/kanbanViewService.ts index 6dc676e351..160044e26a 100644 --- a/packages/nocodb/src/lib/services/kanbanViewService.ts +++ b/packages/nocodb/src/lib/services/kanbanViewService.ts @@ -1,6 +1,6 @@ import { KanbanReqType, ViewTypes } from 'nocodb-sdk'; import { KanbanView, View } from '../models'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; export async function kanbanViewGet(param: { kanbanViewId: string }) { return await KanbanView.get(param.kanbanViewId); @@ -10,7 +10,7 @@ export async function kanbanViewCreate(param: { tableId: string; kanban: KanbanReqType; }) { - Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' }); + T.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' }); const view = await View.insert({ ...param.kanban, // todo: sanitize @@ -24,6 +24,6 @@ export async function kanbanViewUpdate(param: { kanbanViewId: string; kanban: KanbanReqType; }) { - Tele.emit('evt', { evt_type: 'view:updated', type: 'kanban' }); + T.emit('evt', { evt_type: 'view:updated', type: 'kanban' }); return await KanbanView.update(param.kanbanViewId, param.kanban); } diff --git a/packages/nocodb/src/lib/services/mapViewService.ts b/packages/nocodb/src/lib/services/mapViewService.ts index ba21af1b6c..199baa9d13 100644 --- a/packages/nocodb/src/lib/services/mapViewService.ts +++ b/packages/nocodb/src/lib/services/mapViewService.ts @@ -1,18 +1,18 @@ import { MapType, ViewTypes } from 'nocodb-sdk'; import View from '../models/View'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import MapView from '../models/MapView'; -export async function mapViewGet(param:{mapViewId: string}) { - return await MapView.get(param.mapViewId) +export async function mapViewGet(param: { mapViewId: string }) { + return await MapView.get(param.mapViewId); } -export async function mapViewCreate(param:{ - tableId: string, +export async function mapViewCreate(param: { + tableId: string; // todo: add MapReq in schema - map: MapType + map: MapType; }) { - Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'map' }); + T.emit('evt', { evt_type: 'vtable:created', show_as: 'map' }); const view = await View.insert({ ...param.map, // todo: sanitize @@ -22,13 +22,12 @@ export async function mapViewCreate(param:{ return view; } -export async function mapViewUpdate(param:{ - mapViewId: string, +export async function mapViewUpdate(param: { + mapViewId: string; // todo: add MapReq in schema - map: MapType - + map: MapType; }) { - Tele.emit('evt', { evt_type: 'view:updated', type: 'map' }); + T.emit('evt', { evt_type: 'view:updated', type: 'map' }); // todo: type correction - return await MapView.update(param.mapViewId, param.map as any) + return await MapView.update(param.mapViewId, param.map as any); } diff --git a/packages/nocodb/src/lib/services/metaDiffService.ts b/packages/nocodb/src/lib/services/metaDiffService.ts index 0786a0c19a..274ba8e705 100644 --- a/packages/nocodb/src/lib/services/metaDiffService.ts +++ b/packages/nocodb/src/lib/services/metaDiffService.ts @@ -1,6 +1,6 @@ // // Project CRUD -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2'; import { isVirtualCol, ModelTypes, RelationTypes, UITypes } from 'nocodb-sdk'; import { @@ -576,9 +576,7 @@ export async function baseMetaDiff(param: { return changes; } -export async function metaDiffSync(param: { - projectId: string; -}) { +export async function metaDiffSync(param: { projectId: string }) { const project = await Project.getWithInfo(param.projectId); for (const base of project.bases) { const virtualColumnInsert: Array<() => Promise> = []; @@ -777,7 +775,7 @@ export async function metaDiffSync(param: { await extractAndGenerateManyToManyRelations(await base.getModels()); } - Tele.emit('evt', { evt_type: 'metaDiff:synced' }); + T.emit('evt', { evt_type: 'metaDiff:synced' }); return true; } @@ -969,7 +967,7 @@ export async function baseMetaDiffSync(param: { // populate m2m relations await extractAndGenerateManyToManyRelations(await base.getModels()); - Tele.emit('evt', { evt_type: 'baseMetaDiff:synced' }); + T.emit('evt', { evt_type: 'baseMetaDiff:synced' }); return true; } diff --git a/packages/nocodb/src/lib/services/modelVisibilityService.ts b/packages/nocodb/src/lib/services/modelVisibilityService.ts index ad71f02871..95471c0ead 100644 --- a/packages/nocodb/src/lib/services/modelVisibilityService.ts +++ b/packages/nocodb/src/lib/services/modelVisibilityService.ts @@ -2,13 +2,13 @@ import { VisibilityRuleReqType } from 'nocodb-sdk'; import { NcError } from '../meta/helpers/catchError'; import Model from '../models/Model'; import ModelRoleVisibility from '../models/ModelRoleVisibility'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; export async function xcVisibilityMetaSetAll(param: { visibilityRule: VisibilityRuleReqType; projectId: string; }) { - Tele.emit('evt', { evt_type: 'uiAcl:updated' }); + T.emit('evt', { evt_type: 'uiAcl:updated' }); for (const d of param.visibilityRule) { for (const role of Object.keys(d.disabled)) { const view = await Model.get(d.id); @@ -40,7 +40,7 @@ export async function xcVisibilityMetaSetAll(param: { } } } - Tele.emit('evt', { evt_type: 'uiAcl:updated' }); + T.emit('evt', { evt_type: 'uiAcl:updated' }); return true; } diff --git a/packages/nocodb/src/lib/services/orgLicenseService.ts b/packages/nocodb/src/lib/services/orgLicenseService.ts index 7de1f717bf..c39d7814a9 100644 --- a/packages/nocodb/src/lib/services/orgLicenseService.ts +++ b/packages/nocodb/src/lib/services/orgLicenseService.ts @@ -5,13 +5,11 @@ import Noco from '../Noco'; export async function licenseGet() { const license = await Store.get(NC_LICENSE_KEY); - return { key: license?.value } + return { key: license?.value }; } -export async function licenseSet(param:{ - key: string -}) { +export async function licenseSet(param: { key: string }) { await Store.saveOrUpdate({ value: param.key, key: NC_LICENSE_KEY }); await Noco.loadEEState(); - return true + return true; } diff --git a/packages/nocodb/src/lib/services/orgTokenService.ts b/packages/nocodb/src/lib/services/orgTokenService.ts index ede91f0bc6..30228c336a 100644 --- a/packages/nocodb/src/lib/services/orgTokenService.ts +++ b/packages/nocodb/src/lib/services/orgTokenService.ts @@ -1,7 +1,7 @@ import { ApiTokenReqType, OrgUserRoles } from 'nocodb-sdk'; import { User } from '../models'; import ApiToken from '../models/ApiToken'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { NcError } from '../meta/helpers/catchError'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; @@ -32,7 +32,7 @@ export async function apiTokenCreate(param: { user: User; apiToken: ApiTokenReqType; }) { - Tele.emit('evt', { evt_type: 'org:apiToken:created' }); + T.emit('evt', { evt_type: 'org:apiToken:created' }); return await ApiToken.insert({ ...param.apiToken, fk_user_id: param['user'].id, @@ -48,6 +48,6 @@ export async function apiTokenDelete(param: { user: User; token: string }) { ) { NcError.notFound('Token not found'); } - Tele.emit('evt', { evt_type: 'org:apiToken:deleted' }); + T.emit('evt', { evt_type: 'org:apiToken:deleted' }); return await ApiToken.delete(param.token); } diff --git a/packages/nocodb/src/lib/services/orgUserService.ts b/packages/nocodb/src/lib/services/orgUserService.ts index f58e85f890..318afea8c0 100644 --- a/packages/nocodb/src/lib/services/orgUserService.ts +++ b/packages/nocodb/src/lib/services/orgUserService.ts @@ -11,7 +11,7 @@ import { NC_APP_SETTINGS } from '../constants'; import { Audit, ProjectUser, Store, SyncSource, User } from '../models'; import Noco from '../Noco'; import { MetaTable } from '../utils/globals'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { NcError } from '../meta/helpers/catchError'; import { extractProps } from '../meta/helpers/extractProps'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; @@ -142,7 +142,7 @@ export async function userAdd(param: { }); const count = await User.count(); - Tele.emit('evt', { evt_type: 'org:user:invite', count }); + T.emit('evt', { evt_type: 'org:user:invite', count }); await Audit.insert({ op_type: AuditOperationTypes.ORG_USER, diff --git a/packages/nocodb/src/lib/services/pluginService.ts b/packages/nocodb/src/lib/services/pluginService.ts index b468e7240c..2cb885e001 100644 --- a/packages/nocodb/src/lib/services/pluginService.ts +++ b/packages/nocodb/src/lib/services/pluginService.ts @@ -1,30 +1,31 @@ -import { Tele } from 'nc-help'; -import { Plugin } from '../models' -import { PluginTestReqType, PluginType } from 'nocodb-sdk' +import { T } from 'nc-help'; +import { Plugin } from '../models'; +import { PluginTestReqType, PluginType } from 'nocodb-sdk'; import NcPluginMgrv2 from '../meta/helpers/NcPluginMgrv2'; export async function pluginList() { - return await Plugin.list() + return await Plugin.list(); } -export async function pluginTest(param:{body: PluginTestReqType}) { - Tele.emit('evt', { evt_type: 'plugin:tested' }); - return await NcPluginMgrv2.test(param.body) +export async function pluginTest(param: { body: PluginTestReqType }) { + T.emit('evt', { evt_type: 'plugin:tested' }); + return await NcPluginMgrv2.test(param.body); } export async function pluginRead(param: { pluginId: string }) { - return await Plugin.get(param.pluginId) + return await Plugin.get(param.pluginId); } -export async function pluginUpdate( - param: { pluginId: string; plugin: PluginType } -) { +export async function pluginUpdate(param: { + pluginId: string; + plugin: PluginType; +}) { const plugin = await Plugin.update(param.pluginId, param.plugin); - Tele.emit('evt', { + T.emit('evt', { evt_type: plugin.active ? 'plugin:installed' : 'plugin:uninstalled', title: plugin.title, }); - return plugin + return plugin; } export async function isPluginActive(param: { pluginTitle: string }) { - return await Plugin.isPluginActive(param.pluginTitle) + return await Plugin.isPluginActive(param.pluginTitle); } diff --git a/packages/nocodb/src/lib/services/projectService.ts b/packages/nocodb/src/lib/services/projectService.ts index 131df14557..2218f21b34 100644 --- a/packages/nocodb/src/lib/services/projectService.ts +++ b/packages/nocodb/src/lib/services/projectService.ts @@ -1,5 +1,5 @@ import DOMPurify from 'isomorphic-dompurify'; -import { OrgUserRoles, ProjectReqType, } from 'nocodb-sdk'; +import { OrgUserRoles, ProjectReqType } from 'nocodb-sdk'; import { promisify } from 'util'; import { populateMeta } from '../meta/api/helpers'; import { extractPropsAndSanitize } from '../meta/helpers/extractProps'; @@ -95,23 +95,23 @@ export async function projectCreate(param: { for (const base of await project.getBases()) { const info = await populateMeta(base, project); - Tele.emit('evt_api_created', info); + T.emit('evt_api_created', info); delete base.config; } - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:created', xcdb: !projectBody.external, }); - Tele.emit('evt', { evt_type: 'project:rest' }); + T.emit('evt', { evt_type: 'project:rest' }); project; } const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4); -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; export async function getProjectWithInfo(param: { projectId: string }) { const project = await Project.getWithInfo(param.projectId); @@ -120,7 +120,7 @@ export async function getProjectWithInfo(param: { projectId: string }) { export async function projectSoftDelete(param: { projectId: any }) { await Project.softDelete(param.projectId); - Tele.emit('evt', { evt_type: 'project:deleted' }); + T.emit('evt', { evt_type: 'project:deleted' }); return true; } @@ -152,7 +152,7 @@ export async function projectUpdate(param: { } const result = await Project.update(param.projectId, data); - Tele.emit('evt', { evt_type: 'project:update' }); + T.emit('evt', { evt_type: 'project:update' }); return result; } diff --git a/packages/nocodb/src/lib/services/projectUserService.ts b/packages/nocodb/src/lib/services/projectUserService.ts index 1ee50e9410..567568f488 100644 --- a/packages/nocodb/src/lib/services/projectUserService.ts +++ b/packages/nocodb/src/lib/services/projectUserService.ts @@ -1,5 +1,5 @@ import { OrgUserRoles, ProjectUserReqType } from 'nocodb-sdk'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; import ProjectUser from '../models/ProjectUser'; import validator from 'validator'; @@ -109,7 +109,7 @@ export async function userInvite(param: { }); const count = await User.count(); - Tele.emit('evt', { evt_type: 'project:invite', count }); + T.emit('evt', { evt_type: 'project:invite', count }); await Audit.insert({ project_id: param.projectId, diff --git a/packages/nocodb/src/lib/services/sharedBaseService.ts b/packages/nocodb/src/lib/services/sharedBaseService.ts index 637a9e322c..53213d7627 100644 --- a/packages/nocodb/src/lib/services/sharedBaseService.ts +++ b/packages/nocodb/src/lib/services/sharedBaseService.ts @@ -1,4 +1,4 @@ -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { v4 as uuidv4 } from 'uuid'; import Project from '../models/Project'; import { NcError } from '../meta/helpers/catchError'; @@ -7,7 +7,7 @@ const config = { dashboardPath: '/nc', }; -export async function createSharedBaseLink(param:{ +export async function createSharedBaseLink(param: { projectId: string; roles: string; password: string; @@ -34,7 +34,7 @@ export async function createSharedBaseLink(param:{ data.url = `${param.siteUrl}${config.dashboardPath}#/nc/base/${data.uuid}`; delete data.password; - Tele.emit('evt', { evt_type: 'sharedBase:generated-link' }); + T.emit('evt', { evt_type: 'sharedBase:generated-link' }); return data; } @@ -64,11 +64,11 @@ export async function updateSharedBaseLink(param: { data.url = `${param.siteUrl}${config.dashboardPath}#/nc/base/${data.uuid}`; delete data.password; - Tele.emit('evt', { evt_type: 'sharedBase:generated-link' }); + T.emit('evt', { evt_type: 'sharedBase:generated-link' }); return data; } -export async function disableSharedBaseLink(param:{ +export async function disableSharedBaseLink(param: { projectId: string; }): Promise { const project = await Project.get(param.projectId); @@ -82,12 +82,12 @@ export async function disableSharedBaseLink(param:{ await Project.update(project.id, data); - Tele.emit('evt', { evt_type: 'sharedBase:disable-link' }); + T.emit('evt', { evt_type: 'sharedBase:disable-link' }); - return { uuid: null } + return { uuid: null }; } -export async function getSharedBaseLink(param:{ +export async function getSharedBaseLink(param: { projectId: string; siteUrl: string; }): Promise { @@ -105,4 +105,3 @@ export async function getSharedBaseLink(param:{ return data; } - diff --git a/packages/nocodb/src/lib/services/sortService.ts b/packages/nocodb/src/lib/services/sortService.ts index 4d69e278c8..e3931bad2c 100644 --- a/packages/nocodb/src/lib/services/sortService.ts +++ b/packages/nocodb/src/lib/services/sortService.ts @@ -1,21 +1,20 @@ import { SortReqType } from 'nocodb-sdk'; import Sort from '../models/Sort'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; export async function sortGet(param: { sortId: string }) { return Sort.get(param.sortId); } - export async function sortDelete(param: { sortId: string }) { await Sort.delete(param.sortId); - Tele.emit('evt', { evt_type: 'sort:deleted' }); + T.emit('evt', { evt_type: 'sort:deleted' }); return true; } export async function sortUpdate(param: { sortId: any; sort: SortReqType }) { const sort = await Sort.update(param.sortId, param.sort); - Tele.emit('evt', { evt_type: 'sort:updated' }); + T.emit('evt', { evt_type: 'sort:updated' }); return sort; } @@ -24,7 +23,7 @@ export async function sortCreate(param: { viewId: any; sort: SortReqType }) { ...param.sort, fk_view_id: param.viewId, } as Sort); - Tele.emit('evt', { evt_type: 'sort:created' }); + T.emit('evt', { evt_type: 'sort:created' }); return sort; } diff --git a/packages/nocodb/src/lib/services/swaggerService/getSwaggerJSON.ts b/packages/nocodb/src/lib/services/swaggerService/getSwaggerJSON.ts index 9ad9cdbcf6..8d4e81f478 100644 --- a/packages/nocodb/src/lib/services/swaggerService/getSwaggerJSON.ts +++ b/packages/nocodb/src/lib/services/swaggerService/getSwaggerJSON.ts @@ -1,4 +1,4 @@ -import { Model, Project, View } from '../../models' +import { Model, Project, View } from '../../models'; import FormViewColumn from '../../models/FormViewColumn'; import GalleryViewColumn from '../../models/GalleryViewColumn'; import Noco from '../../Noco'; diff --git a/packages/nocodb/src/lib/services/swaggerService/index.ts b/packages/nocodb/src/lib/services/swaggerService/index.ts index 7ee1c073d4..4b46830bf4 100644 --- a/packages/nocodb/src/lib/services/swaggerService/index.ts +++ b/packages/nocodb/src/lib/services/swaggerService/index.ts @@ -1,9 +1,12 @@ -import { NcError } from '../../meta/helpers/catchError' -import Model from '../../models/Model' -import Project from '../../models/Project' -import getSwaggerJSON from './getSwaggerJSON' +import { NcError } from '../../meta/helpers/catchError'; +import Model from '../../models/Model'; +import Project from '../../models/Project'; +import getSwaggerJSON from './getSwaggerJSON'; -export async function swaggerJson(param:{projectId:string; siteUrl:string}){ +export async function swaggerJson(param: { + projectId: string; + siteUrl: string; +}) { const project = await Project.get(param.projectId); if (!project) NcError.notFound(); diff --git a/packages/nocodb/src/lib/services/syncService/helpers/job.ts b/packages/nocodb/src/lib/services/syncService/helpers/job.ts index 80820cfeaf..b956a5353c 100644 --- a/packages/nocodb/src/lib/services/syncService/helpers/job.ts +++ b/packages/nocodb/src/lib/services/syncService/helpers/job.ts @@ -1,4 +1,4 @@ -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import FetchAT from './fetchAT'; import { UITypes } from 'nocodb-sdk'; // import * as sMap from './syncMap'; @@ -1933,7 +1933,7 @@ export default async ( }); } - Tele.event({ + T.event({ event: 'a:airtable-import:success', data: { stats: { @@ -2386,7 +2386,7 @@ export default async ( } } catch (e) { if (e.response?.data?.msg) { - Tele.event({ + T.event({ event: 'a:airtable-import:error', data: { error: e.response.data.msg }, }); diff --git a/packages/nocodb/src/lib/services/syncService/index.ts b/packages/nocodb/src/lib/services/syncService/index.ts index ddd27adcfd..1c1f17b177 100644 --- a/packages/nocodb/src/lib/services/syncService/index.ts +++ b/packages/nocodb/src/lib/services/syncService/index.ts @@ -1,6 +1,6 @@ -import { Tele } from 'nc-help'; -import { PagedResponseImpl } from '../../meta/helpers/PagedResponse' -import { Project, SyncSource } from '../../models' +import { T } from 'nc-help'; +import { PagedResponseImpl } from '../../meta/helpers/PagedResponse'; +import { Project, SyncSource } from '../../models'; export async function syncSourceList(param: { projectId: string; @@ -18,7 +18,7 @@ export async function syncCreate(param: { // todo: define type syncPayload: Partial; }) { - Tele.emit('evt', { evt_type: 'webhooks:created' }); + T.emit('evt', { evt_type: 'webhooks:created' }); const project = await Project.getWithInfo(param.projectId); const sync = await SyncSource.insert({ @@ -31,17 +31,17 @@ export async function syncCreate(param: { } export async function syncDelete(param: { syncId: string }) { - Tele.emit('evt', { evt_type: 'webhooks:deleted' }); - return await SyncSource.delete(param.syncId) + T.emit('evt', { evt_type: 'webhooks:deleted' }); + return await SyncSource.delete(param.syncId); } -export async function syncUpdate(param:{ +export async function syncUpdate(param: { syncId: string; syncPayload: Partial; }) { - Tele.emit('evt', { evt_type: 'webhooks:updated' }); + T.emit('evt', { evt_type: 'webhooks:updated' }); - return await SyncSource.update(param.syncId, param.syncPayload) + return await SyncSource.update(param.syncId, param.syncPayload); } export { default as airtableImportJob } from './helpers/job'; diff --git a/packages/nocodb/src/lib/services/tableService.ts b/packages/nocodb/src/lib/services/tableService.ts index a3459860fc..883927583f 100644 --- a/packages/nocodb/src/lib/services/tableService.ts +++ b/packages/nocodb/src/lib/services/tableService.ts @@ -26,7 +26,7 @@ import Project from '../models/Project'; import User from '../models/User'; import View from '../models/View'; import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; export function reorderTable(param: { tableId: string; order: any }) { return Model.updateOrder(param.tableId, param.order); @@ -84,7 +84,7 @@ export async function tableDelete(param: { tableId: string; user: User }) { // ip: (req as any).clientIp, }).then(() => {}); - Tele.emit('evt', { evt_type: 'table:deleted' }); + T.emit('evt', { evt_type: 'table:deleted' }); return table.delete(); } @@ -319,8 +319,9 @@ export async function tableCreate(args: { mapDefaultDisplayValue(args.table.columns); - Tele.emit('evt', { evt_type: 'table:created' }); + T.emit('evt', { evt_type: 'table:created' }); + // todo: type correction const result = await Model.insert(project.id, base.id, { ...args.table, columns: columns.map((c, i) => { @@ -342,7 +343,7 @@ export async function tableCreate(args: { } as NormalColumnRequestType; }), order: +(tables?.pop()?.order ?? 0) + 1, - }); + } as any); return result; } diff --git a/packages/nocodb/src/lib/services/userService/helpers.ts b/packages/nocodb/src/lib/services/userService/helpers.ts index 4cfe0bd687..90e2d81dfc 100644 --- a/packages/nocodb/src/lib/services/userService/helpers.ts +++ b/packages/nocodb/src/lib/services/userService/helpers.ts @@ -1,7 +1,7 @@ import * as jwt from 'jsonwebtoken'; import crypto from 'crypto'; -import { NcConfig } from '../../../interface/config' -import { User } from '../../models' +import { NcConfig } from '../../../interface/config'; +import { User } from '../../models'; export function genJwt(user: User, config: NcConfig) { return jwt.sign( diff --git a/packages/nocodb/src/lib/services/userService/index.ts b/packages/nocodb/src/lib/services/userService/index.ts index 73b9a9948c..c18d35bd2e 100644 --- a/packages/nocodb/src/lib/services/userService/index.ts +++ b/packages/nocodb/src/lib/services/userService/index.ts @@ -1,46 +1,35 @@ -import { Request, Response } from 'express'; import { PasswordChangeReqType, - PasswordForgotReqType, PasswordResetReqType, - SignUpReqType, - TableType, + PasswordForgotReqType, + PasswordResetReqType, UserType, validatePassword, -} from 'nocodb-sdk' +} from 'nocodb-sdk'; import { OrgUserRoles } from 'nocodb-sdk'; -import { NC_APP_SETTINGS } from '../../../constants'; -import Store from '../../../models/Store'; -import { Tele } from 'nc-help'; -import catchError, { NcError } from '../../helpers/catchError'; +import { T } from 'nc-help'; -const { isEmail } = require('validator'); import * as ejs from 'ejs'; import bcrypt from 'bcryptjs'; import { promisify } from 'util'; -import User from '../../../models/User'; +import { NC_APP_SETTINGS } from '../../constants'; +import { NcError } from '../../meta/helpers/catchError'; +import NcPluginMgrv2 from '../../meta/helpers/NcPluginMgrv2'; +import { Audit, Store, User } from '../../models'; +import Noco from '../../Noco'; +import { MetaTable } from '../../utils/globals'; +import { randomTokenString } from './helpers'; const { v4: uuidv4 } = require('uuid'); -import Audit from '../../../models/Audit'; -import NcPluginMgrv2 from '../../helpers/NcPluginMgrv2'; - -import passport from 'passport'; -import extractProjectIdAndAuthenticate from '../../helpers/extractProjectIdAndAuthenticate'; -import ncMetaAclMw from '../../helpers/ncMetaAclMw'; -import { MetaTable } from '../../../utils/globals'; -import Noco from '../../../Noco'; -import { getAjvValidatorMw } from '../helpers'; -import { genJwt } from './helpers'; -import { randomTokenString } from '../../helpers/stringHelpers'; export async function registerNewUserIfAllowed({ - firstname, - lastname, - email, - salt, - password, - email_verification_token, - }: { + firstname, + lastname, + email, + salt, + password, + email_verification_token, +}: { firstname; lastname; email: string; @@ -54,7 +43,7 @@ export async function registerNewUserIfAllowed({ roles = `${OrgUserRoles.CREATOR},${OrgUserRoles.SUPER_ADMIN}`; // todo: update in nc_store // roles = 'owner,creator,editor' - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:invite', count: 1, }); @@ -85,11 +74,10 @@ export async function registerNewUserIfAllowed({ }); } - export async function passwordChange(param: { - body: PasswordChangeReqType - user: UserType - req:any + body: PasswordChangeReqType; + user: UserType; + req: any; }): Promise { const { currentPassword, newPassword } = param.body; @@ -133,13 +121,13 @@ export async function passwordChange(param: { ip: param.req?.clientIp, }); - return true + return true; } -export async function passwordForgot(param:{ +export async function passwordForgot(param: { body: PasswordForgotReqType; siteUrl: string; - req:any + req: any; }): Promise { const _email = param.body.email; @@ -165,9 +153,7 @@ export async function passwordForgot(param:{ adapter.mailSend({ to: user.email, subject: 'Password Reset Link', - text: `Visit following link to update your password : ${ - param.siteUrl - }/auth/password/reset/${token}.`, + text: `Visit following link to update your password : ${param.siteUrl}/auth/password/reset/${token}.`, html: ejs.render(template, { resetLink: param.siteUrl + `/auth/password/reset/${token}`, }), @@ -191,12 +177,10 @@ export async function passwordForgot(param:{ return NcError.badRequest('Your email has not been registered.'); } - return true + return true; } -export async function tokenValidate(param:{ - token: string; -}): Promise { +export async function tokenValidate(param: { token: string }): Promise { const token = param.token; const user = await Noco.ncMeta.metaGet(null, null, MetaTable.USERS, { @@ -210,14 +194,14 @@ export async function tokenValidate(param:{ NcError.badRequest('Password reset url expired'); } - return true + return true; } -export async function passwordReset(param:{ +export async function passwordReset(param: { body: PasswordResetReqType; token: string; // todo: exclude - req:any; + req: any; }): Promise { const { token, body, req } = param; @@ -261,7 +245,7 @@ export async function passwordReset(param:{ ip: req.clientIp, }); - return true + return true; } export async function emailVerification(param: { @@ -293,9 +277,8 @@ export async function emailVerification(param: { ip: req.clientIp, }); - return true + return true; } -export * from './helpers' -export * from './initAdminFromEnv' - +export * from './helpers'; +export { default as initAdminFromEnv } from './initAdminFromEnv'; diff --git a/packages/nocodb/src/lib/services/userService/initAdminFromEnv.ts b/packages/nocodb/src/lib/services/userService/initAdminFromEnv.ts index 8f9bfdce74..1a15b94649 100644 --- a/packages/nocodb/src/lib/services/userService/initAdminFromEnv.ts +++ b/packages/nocodb/src/lib/services/userService/initAdminFromEnv.ts @@ -1,15 +1,14 @@ -import User from '../../../models/User'; import { v4 as uuidv4 } from 'uuid'; import { promisify } from 'util'; import bcrypt from 'bcryptjs'; -import Noco from '../../../Noco'; -import { CacheScope, MetaTable } from '../../../utils/globals'; -import ProjectUser from '../../../models/ProjectUser'; import { validatePassword } from 'nocodb-sdk'; import boxen from 'boxen'; -import NocoCache from '../../../cache/NocoCache'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; +import NocoCache from '../../cache/NocoCache'; +import { ProjectUser, User } from '../../models'; +import Noco from '../../Noco'; +import { CacheScope, MetaTable } from '../../utils/globals'; const { isEmail } = require('validator'); const rolesLevel = { owner: 0, creator: 1, editor: 2, commenter: 3, viewer: 4 }; @@ -68,7 +67,7 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) { // if super admin not present if (await User.isFirst(ncMeta)) { // roles = 'owner,creator,editor' - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:invite', count: 1, }); @@ -126,7 +125,7 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) { ncMeta ); } else { - Tele.emit('evt', { + T.emit('evt', { evt_type: 'project:invite', count: 1, }); diff --git a/packages/nocodb/src/lib/services/userService/ui/auth/emailVerify.ts b/packages/nocodb/src/lib/services/userService/ui/auth/emailVerify.ts new file mode 100644 index 0000000000..f7412b12ba --- /dev/null +++ b/packages/nocodb/src/lib/services/userService/ui/auth/emailVerify.ts @@ -0,0 +1,70 @@ +export default ` + + + NocoDB - Verify Email + + + + + + + +
+ + + + + + Email verified successfully! + + + {{errMsg}} + + + + + + + +
+ + + + + +`; diff --git a/packages/nocodb/src/lib/services/userService/ui/auth/resetPassword.ts b/packages/nocodb/src/lib/services/userService/ui/auth/resetPassword.ts new file mode 100644 index 0000000000..514fc6d739 --- /dev/null +++ b/packages/nocodb/src/lib/services/userService/ui/auth/resetPassword.ts @@ -0,0 +1,108 @@ +export default ` + + + NocoDB - Reset Password + + + + + + + +
+ + + + + + Password reset successful! + + + + + + +
+ + + + + +`; diff --git a/packages/nocodb/src/lib/services/userService/ui/emailTemplates/forgotPassword.ts b/packages/nocodb/src/lib/services/userService/ui/emailTemplates/forgotPassword.ts new file mode 100644 index 0000000000..afb2f5849a --- /dev/null +++ b/packages/nocodb/src/lib/services/userService/ui/emailTemplates/forgotPassword.ts @@ -0,0 +1,171 @@ +export default ` + + + + + Simple Transactional Email + + + + + + + + + + + + + +`; diff --git a/packages/nocodb/src/lib/services/userService/ui/emailTemplates/invite.ts b/packages/nocodb/src/lib/services/userService/ui/emailTemplates/invite.ts new file mode 100644 index 0000000000..fc81f9409e --- /dev/null +++ b/packages/nocodb/src/lib/services/userService/ui/emailTemplates/invite.ts @@ -0,0 +1,208 @@ +export default ` + + + + + Simple Transactional Email + + + + + + + + + + + + + +`; diff --git a/packages/nocodb/src/lib/services/userService/ui/emailTemplates/verify.ts b/packages/nocodb/src/lib/services/userService/ui/emailTemplates/verify.ts new file mode 100644 index 0000000000..11702cc659 --- /dev/null +++ b/packages/nocodb/src/lib/services/userService/ui/emailTemplates/verify.ts @@ -0,0 +1,207 @@ +export default ` + + + + + Simple Transactional Email + + + + + + + + + + + + + +`; diff --git a/packages/nocodb/src/lib/services/utilService.ts b/packages/nocodb/src/lib/services/utilService.ts index 14c42094f1..b19eca2cf5 100644 --- a/packages/nocodb/src/lib/services/utilService.ts +++ b/packages/nocodb/src/lib/services/utilService.ts @@ -20,9 +20,7 @@ const versionCache = { lastFetched: null, }; - - -export async function testConnection(param:{body: any}) { +export async function testConnection(param: { body: any }) { return await SqlMgrv2.testConnection(param.body); } diff --git a/packages/nocodb/src/lib/services/viewColumnService.ts b/packages/nocodb/src/lib/services/viewColumnService.ts index f6825691ad..73d2041d46 100644 --- a/packages/nocodb/src/lib/services/viewColumnService.ts +++ b/packages/nocodb/src/lib/services/viewColumnService.ts @@ -1,5 +1,5 @@ -import { Tele } from 'nc-help'; -import { View } from '../models' +import { T } from 'nc-help'; +import { View } from '../models'; export async function columnList(param: { viewId: string }) { return await View.getColumns(param.viewId); @@ -18,7 +18,7 @@ export async function columnAdd(param: { view_id: param.viewId, } ); - Tele.emit('evt', { evt_type: 'viewColumn:inserted' }); + T.emit('evt', { evt_type: 'viewColumn:inserted' }); return viewColumn; } @@ -34,6 +34,6 @@ export async function columnUpdate(param: { param.columnId, param.column ); - Tele.emit('evt', { evt_type: 'viewColumn:updated' }); + T.emit('evt', { evt_type: 'viewColumn:updated' }); return result; } diff --git a/packages/nocodb/src/lib/services/viewService.ts b/packages/nocodb/src/lib/services/viewService.ts index 66b3aba3c4..f328d5bab8 100644 --- a/packages/nocodb/src/lib/services/viewService.ts +++ b/packages/nocodb/src/lib/services/viewService.ts @@ -1,6 +1,6 @@ +import { SharedViewType, ViewType } from 'nocodb-sdk'; import { Model, View } from '../models'; -import { Tele } from 'nc-help'; -import { SharedViewReqType, ViewReqType } from 'nocodb-sdk'; +import { T } from 'nc-help'; import { xcVisibilityMetaGet } from './modelVisibilityService'; export async function viewList(param: { @@ -11,12 +11,10 @@ export async function viewList(param: { }) { const model = await Model.get(param.tableId); - const viewList = await xcVisibilityMetaGet( - // param.projectId, - // param.baseId, - model.project_id, - [model] - ); + const viewList = await xcVisibilityMetaGet({ + projectId: model.project_id, + models: [model], + }); // todo: user roles //await View.list(param.tableId) @@ -31,34 +29,34 @@ export async function viewList(param: { // @ts-ignore export async function shareView(param: { viewId: string }) { - Tele.emit('evt', { evt_type: 'sharedView:generated-link' }); + T.emit('evt', { evt_type: 'sharedView:generated-link' }); return await View.share(param.viewId); } -// @ts-ignore -export async function viewUpdate(param: { viewId: string; view: ViewReqType }) { +// todo: type correctly +export async function viewUpdate(param: { viewId: string; view: ViewType }) { const result = await View.update(param.viewId, param.view); - Tele.emit('evt', { evt_type: 'vtable:updated', show_as: result.type }); + T.emit('evt', { evt_type: 'vtable:updated', show_as: result.type }); return result; } -// @ts-ignore export async function viewDelete(param: { viewId: string }) { await View.delete(param.viewId); - Tele.emit('evt', { evt_type: 'vtable:deleted' }); + T.emit('evt', { evt_type: 'vtable:deleted' }); return true; } export async function shareViewUpdate(param: { viewId: string; - sharedView: SharedViewReqType; + // todo: type correctly + sharedView: SharedViewType; }) { - Tele.emit('evt', { evt_type: 'sharedView:updated' }); + T.emit('evt', { evt_type: 'sharedView:updated' }); return await View.update(param.viewId, param.sharedView); } export async function shareViewDelete(param: { viewId: string }) { - Tele.emit('evt', { evt_type: 'sharedView:deleted' }); + T.emit('evt', { evt_type: 'sharedView:deleted' }); await View.sharedViewDelete(param.viewId); return true; } diff --git a/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts b/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts index 69294bdfc3..5b1f36e8a2 100644 --- a/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts +++ b/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts @@ -21,7 +21,7 @@ import NcProjectBuilder from '../../v1-legacy/NcProjectBuilder'; import Noco from '../../Noco'; import NcMetaIO from '../../meta/NcMetaIO'; import XcCache from '../../v1-legacy/plugins/adapters/cache/XcCache'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import BaseModel from './BaseModel'; import { XcCron } from './XcCron'; @@ -324,7 +324,7 @@ export default abstract class BaseApiBuilder } ); } - Tele.emit('evt', { evt_type: 'relation:created' }); + T.emit('evt', { evt_type: 'relation:created' }); } public async onRelationDelete( @@ -2979,7 +2979,7 @@ export default abstract class BaseApiBuilder } public async onTableCreate(_tn: string, _args?: any) { - Tele.emit('evt', { evt_type: 'table:created' }); + T.emit('evt', { evt_type: 'table:created' }); } public onVirtualTableUpdate(args: any) { diff --git a/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts b/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts index e155f40c15..15a63e4a6a 100644 --- a/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts +++ b/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts @@ -10,7 +10,7 @@ import SqlClientFactory from '../db/sql-client/lib/SqlClientFactory'; import Migrator from '../db/sql-migrator/lib/KnexMigrator'; import Noco from '../Noco'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import { GqlApiBuilder } from './gql/GqlApiBuilder'; import { XCEeError } from '../meta/NcMetaMgr'; import { RestApiBuilder } from './rest/RestApiBuilder'; @@ -840,7 +840,7 @@ export default class NcProjectBuilder { this.apiInfInfoList.push(info); this.aggregatedApiInfo = aggregatedInfo; if (isFirstTime) { - Tele.emit('evt_api_created', info); + T.emit('evt_api_created', info); } } diff --git a/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts b/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts index f78c17cd5c..1c8f61268c 100644 --- a/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts +++ b/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts @@ -29,7 +29,7 @@ const { isEmail } = require('validator'); import axios from 'axios'; import IEmailAdapter from '../../../interface/IEmailAdapter'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import XcCache from '../plugins/adapters/cache/XcCache'; passport.serializeUser(function ( @@ -130,7 +130,7 @@ export default class RestAuthCtrl { await this.createAuthTableIfNotExists(); await this.initStrategies(); - Tele.emit('evt_app_started', await this.users.count('id as count').first()); + T.emit('evt_app_started', await this.users.count('id as count').first()); this.app.router.use(passport.initialize()); const jwtMiddleware = passport.authenticate('jwt', { session: false }); @@ -406,7 +406,7 @@ export default class RestAuthCtrl { const token = req.query.state; if (token) { - Tele.emit('evt_subscribe', email); + T.emit('evt_subscribe', email); await this.users .update({ // firstname, lastname, @@ -431,7 +431,7 @@ export default class RestAuthCtrl { return cb({ msg: `Account not found!` }); } - Tele.emit('evt_subscribe', email); + T.emit('evt_subscribe', email); const salt = await promisify(bcrypt.genSalt)(10); user = await this.users.insert({ email: profile.emails[0].value, @@ -513,7 +513,7 @@ export default class RestAuthCtrl { const token = req.query?.state?.replace('github|', ''); if (token) { - Tele.emit('evt_subscribe', email); + T.emit('evt_subscribe', email); await this.users .update({ // firstname, lastname, @@ -538,7 +538,7 @@ export default class RestAuthCtrl { return cb({ msg: `Account not found!` }); } - Tele.emit('evt_subscribe', email); + T.emit('evt_subscribe', email); const salt = await promisify(bcrypt.genSalt)(10); user = await this.users.insert({ email: profile.emails[0].value, @@ -900,7 +900,7 @@ export default class RestAuthCtrl { const email_verification_token = uuidv4(); if (!ignore_subscribe) { - Tele.emit('evt_subscribe', email); + T.emit('evt_subscribe', email); } if (user) { @@ -928,7 +928,7 @@ export default class RestAuthCtrl { if (!(await this.users.first())) { // todo: update in nc_store // roles = 'owner,creator,editor' - Tele.emit('evt', { evt_type: 'project:invite', count: 1 }); + T.emit('evt', { evt_type: 'project:invite', count: 1 }); } else { if (process.env.NC_INVITE_ONLY_SIGNUP) { return next( @@ -1289,7 +1289,7 @@ export default class RestAuthCtrl { } } - Tele.emit('evt', { evt_type: 'project:invite', count: count?.count }); + T.emit('evt', { evt_type: 'project:invite', count: count?.count }); this.xcMeta.audit(req.body.project_id, null, 'nc_audit', { op_type: 'AUTHENTICATION', op_sub_type: 'INVITE', diff --git a/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrlEE.ts b/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrlEE.ts index a91eeb5558..efeae0b567 100644 --- a/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrlEE.ts +++ b/packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrlEE.ts @@ -2,7 +2,7 @@ import passport from 'passport'; import { Strategy } from 'passport-jwt'; import { v4 as uuidv4 } from 'uuid'; import validator from 'validator'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import XcCache from '../plugins/adapters/cache/XcCache'; @@ -85,7 +85,7 @@ export default class RestAuthCtrlEE extends RestAuthCtrl { req.body.roles ); - Tele.emit('evt', { evt_type: 'project:invite', count: count?.count }); + T.emit('evt', { evt_type: 'project:invite', count: count?.count }); this.xcMeta.audit(req.body.project_id, null, 'nc_audit', { op_type: 'AUTHENTICATION', diff --git a/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts b/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts index e4354301eb..7a1c945f22 100644 --- a/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts +++ b/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts @@ -2,7 +2,7 @@ import { NcConfig } from '../../interface/config'; import debug from 'debug'; import NcMetaIO from '../meta/NcMetaIO'; -import { Tele } from 'nc-help'; +import { T } from 'nc-help'; import ncProjectEnvUpgrader from './ncProjectEnvUpgrader'; import ncProjectEnvUpgrader0011045 from './ncProjectEnvUpgrader0011045'; import ncProjectUpgraderV2_0090000 from './ncProjectUpgraderV2_0090000'; @@ -107,14 +107,14 @@ export default class NcUpgrader { } } await ctx.ncMeta.commit(); - Tele.emit('evt', { + T.emit('evt', { evt_type: 'appMigration:upgraded', from: oldVersion, to: process.env.NC_VERSION, }); } catch (e) { await ctx.ncMeta.rollback(e); - Tele.emit('evt', { + T.emit('evt', { evt_type: 'appMigration:failed', from: oldVersion, to: process.env.NC_VERSION,