From 65d7656097935a6593408e9fae0cc3dce2a4c554 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 11 Jul 2024 15:27:48 +0200 Subject: [PATCH] Unify newid --- packages/server/src/api/controllers/deploy/Deployment.ts | 5 ++--- packages/server/src/automations/utils.ts | 5 ++--- packages/server/src/db/inMemoryView.ts | 5 ++--- packages/server/src/db/newid.ts | 5 ----- packages/server/src/db/utils.ts | 5 +++-- packages/server/src/tests/utilities/TestConfiguration.ts | 4 +++- 6 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 packages/server/src/db/newid.ts diff --git a/packages/server/src/api/controllers/deploy/Deployment.ts b/packages/server/src/api/controllers/deploy/Deployment.ts index 611c82f28b..fe817730b6 100644 --- a/packages/server/src/api/controllers/deploy/Deployment.ts +++ b/packages/server/src/api/controllers/deploy/Deployment.ts @@ -1,5 +1,4 @@ -import newid from "../../../db/newid" -import { context } from "@budibase/backend-core" +import { context, utils } from "@budibase/backend-core" /** * This is used to pass around information about the deployment that is occurring @@ -12,7 +11,7 @@ export default class Deployment { appUrl?: string constructor(id = null) { - this._id = id || newid() + this._id = id || utils.newid() } setVerification(verification: any) { diff --git a/packages/server/src/automations/utils.ts b/packages/server/src/automations/utils.ts index 4d7e169f52..784632b626 100644 --- a/packages/server/src/automations/utils.ts +++ b/packages/server/src/automations/utils.ts @@ -1,10 +1,9 @@ import { Thread, ThreadType } from "../threads" import { definitions } from "./triggerInfo" import { automationQueue } from "./bullboard" -import newid from "../db/newid" import { updateEntityMetadata } from "../utilities" import { MetadataTypes } from "../constants" -import { db as dbCore, context } from "@budibase/backend-core" +import { db as dbCore, context, utils } from "@budibase/backend-core" import { getAutomationMetadataParams } from "../db/utils" import { cloneDeep } from "lodash/fp" import { quotas } from "@budibase/pro" @@ -207,7 +206,7 @@ export async function enableCronTrigger(appId: any, automation: Automation) { ) } // make a job id rather than letting Bull decide, makes it easier to handle on way out - const jobId = `${appId}_cron_${newid()}` + const jobId = `${appId}_cron_${utils.newid()}` const job: any = await automationQueue.add( { automation, diff --git a/packages/server/src/db/inMemoryView.ts b/packages/server/src/db/inMemoryView.ts index 73e5c622eb..525c4b456e 100644 --- a/packages/server/src/db/inMemoryView.ts +++ b/packages/server/src/db/inMemoryView.ts @@ -1,9 +1,8 @@ -import newid from "./newid" import { Row, Document, DBView } from "@budibase/types" // bypass the main application db config // use in memory pouchdb directly -import { db as dbCore } from "@budibase/backend-core" +import { db as dbCore, utils } from "@budibase/backend-core" const Pouch = dbCore.getPouch({ inMemory: true }) @@ -16,7 +15,7 @@ export async function runView( // use a different ID each time for the DB, make sure they // are always unique for each query, don't want overlap // which could cause 409s - const db = new Pouch(newid()) + const db = new Pouch(utils.newid()) try { // write all the docs to the in memory Pouch (remove revs) await db.bulkDocs( diff --git a/packages/server/src/db/newid.ts b/packages/server/src/db/newid.ts deleted file mode 100644 index bc8f3bb04b..0000000000 --- a/packages/server/src/db/newid.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { v4 } from "uuid" - -export default function (): string { - return v4().replace(/-/g, "") -} diff --git a/packages/server/src/db/utils.ts b/packages/server/src/db/utils.ts index 32e72ffad7..3ee787b50d 100644 --- a/packages/server/src/db/utils.ts +++ b/packages/server/src/db/utils.ts @@ -1,5 +1,4 @@ -import newid from "./newid" -import { context, db as dbCore } from "@budibase/backend-core" +import { context, db as dbCore, utils } from "@budibase/backend-core" import { DatabaseQueryOpts, Datasource, @@ -15,6 +14,8 @@ import { export { DocumentType, VirtualDocumentType } from "@budibase/types" +const newid = utils.newid + type Optional = string | null export const enum AppStatus { diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 828b389add..3d53149385 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -26,6 +26,7 @@ import { roles, sessions, tenancy, + utils, } from "@budibase/backend-core" import { app as appController, @@ -40,7 +41,6 @@ import { } from "./controllers" import { cleanup } from "../../utilities/fileSystem" -import newid from "../../db/newid" import { generateUserMetadataID } from "../../db/utils" import { startup } from "../../startup" import supertest from "supertest" @@ -74,6 +74,8 @@ import { cloneDeep } from "lodash" import jwt, { Secret } from "jsonwebtoken" import { Server } from "http" +const newid = utils.newid + mocks.licenses.init(pro) // use unlimited license by default