Merge pull request #14151 from Budibase/chore/unify-utils

Unify duplicated newid utils
This commit is contained in:
Adria Navarro 2024-07-12 11:46:18 +02:00 committed by GitHub
commit 5ff9599e3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 12 additions and 17 deletions

View File

@ -1,5 +1,4 @@
import newid from "../../../db/newid" import { context, utils } from "@budibase/backend-core"
import { context } from "@budibase/backend-core"
/** /**
* This is used to pass around information about the deployment that is occurring * This is used to pass around information about the deployment that is occurring
@ -12,7 +11,7 @@ export default class Deployment {
appUrl?: string appUrl?: string
constructor(id = null) { constructor(id = null) {
this._id = id || newid() this._id = id || utils.newid()
} }
setVerification(verification: any) { setVerification(verification: any) {

View File

@ -1,10 +1,9 @@
import { Thread, ThreadType } from "../threads" import { Thread, ThreadType } from "../threads"
import { definitions } from "./triggerInfo" import { definitions } from "./triggerInfo"
import { automationQueue } from "./bullboard" import { automationQueue } from "./bullboard"
import newid from "../db/newid"
import { updateEntityMetadata } from "../utilities" import { updateEntityMetadata } from "../utilities"
import { MetadataTypes } from "../constants" 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 { getAutomationMetadataParams } from "../db/utils"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { quotas } from "@budibase/pro" 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 // 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( const job: any = await automationQueue.add(
{ {
automation, automation,

View File

@ -1,9 +1,8 @@
import newid from "./newid"
import { Row, Document, DBView } from "@budibase/types" import { Row, Document, DBView } from "@budibase/types"
// bypass the main application db config // bypass the main application db config
// use in memory pouchdb directly // 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 }) 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 // use a different ID each time for the DB, make sure they
// are always unique for each query, don't want overlap // are always unique for each query, don't want overlap
// which could cause 409s // which could cause 409s
const db = new Pouch(newid()) const db = new Pouch(utils.newid())
try { try {
// write all the docs to the in memory Pouch (remove revs) // write all the docs to the in memory Pouch (remove revs)
await db.bulkDocs( await db.bulkDocs(

View File

@ -1,5 +0,0 @@
import { v4 } from "uuid"
export default function (): string {
return v4().replace(/-/g, "")
}

View File

@ -1,5 +1,4 @@
import newid from "./newid" import { context, db as dbCore, utils } from "@budibase/backend-core"
import { context, db as dbCore } from "@budibase/backend-core"
import { import {
DatabaseQueryOpts, DatabaseQueryOpts,
Datasource, Datasource,
@ -15,6 +14,8 @@ import {
export { DocumentType, VirtualDocumentType } from "@budibase/types" export { DocumentType, VirtualDocumentType } from "@budibase/types"
const newid = utils.newid
type Optional = string | null type Optional = string | null
export const enum AppStatus { export const enum AppStatus {

View File

@ -26,6 +26,7 @@ import {
roles, roles,
sessions, sessions,
tenancy, tenancy,
utils,
} from "@budibase/backend-core" } from "@budibase/backend-core"
import { import {
app as appController, app as appController,
@ -40,7 +41,6 @@ import {
} from "./controllers" } from "./controllers"
import { cleanup } from "../../utilities/fileSystem" import { cleanup } from "../../utilities/fileSystem"
import newid from "../../db/newid"
import { generateUserMetadataID } from "../../db/utils" import { generateUserMetadataID } from "../../db/utils"
import { startup } from "../../startup" import { startup } from "../../startup"
import supertest from "supertest" import supertest from "supertest"
@ -74,6 +74,8 @@ import { cloneDeep } from "lodash"
import jwt, { Secret } from "jsonwebtoken" import jwt, { Secret } from "jsonwebtoken"
import { Server } from "http" import { Server } from "http"
const newid = utils.newid
mocks.licenses.init(pro) mocks.licenses.init(pro)
// use unlimited license by default // use unlimited license by default