diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index b79ca0e581..c4b49d1f74 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -1,7 +1,7 @@ const CouchDB = require("../../db") const ClientDb = require("../../db/clientDb") const { getPackageForBuilder } = require("../../utilities/builder") -const uuid = require("uuid") +const newid = require("../../db/newid") const env = require("../../environment") exports.fetch = async function(ctx) { @@ -24,7 +24,7 @@ exports.create = async function(ctx) { const db = new CouchDB(ClientDb.name(env.CLIENT_ID)) const newApplication = { - _id: uuid.v4().replace(/-/g, ""), + _id: newid(), type: "app", instances: [], userInstanceMap: {}, diff --git a/packages/server/src/api/controllers/instance.js b/packages/server/src/api/controllers/instance.js index dcfc1ba2dc..ba03c6c352 100644 --- a/packages/server/src/api/controllers/instance.js +++ b/packages/server/src/api/controllers/instance.js @@ -1,12 +1,11 @@ const CouchDB = require("../../db") const client = require("../../db/clientDb") -const uuid = require("uuid") +const newid = require("../../db/newid") const env = require("../../environment") exports.create = async function(ctx) { const instanceName = ctx.request.body.name - const uid = uuid.v4().replace(/-/g, "") - const instanceId = `inst_${ctx.params.applicationId.substring(0, 7)}_${uid}` + const instanceId = `inst_${ctx.params.applicationId.substring(0, 7)}_${newid()}` const { applicationId } = ctx.params const clientId = env.CLIENT_ID const db = new CouchDB(instanceId) diff --git a/packages/server/src/api/controllers/model.js b/packages/server/src/api/controllers/model.js index 4a97cf97aa..a30026a645 100644 --- a/packages/server/src/api/controllers/model.js +++ b/packages/server/src/api/controllers/model.js @@ -1,5 +1,5 @@ const CouchDB = require("../../db") -const uuid = require("uuid") +const newid = require("../../db/newid") exports.fetch = async function(ctx) { const db = new CouchDB(ctx.params.instanceId) @@ -15,7 +15,7 @@ exports.create = async function(ctx) { const newModel = { type: "model", ...ctx.request.body, - _id: uuid.v4().replace(/-/g, ""), + _id: newid(), } const result = await db.post(newModel) diff --git a/packages/server/src/api/controllers/record.js b/packages/server/src/api/controllers/record.js index b6b7fc62b3..2cd648b6c3 100644 --- a/packages/server/src/api/controllers/record.js +++ b/packages/server/src/api/controllers/record.js @@ -1,6 +1,6 @@ const CouchDB = require("../../db") const Ajv = require("ajv") -const uuid = require("uuid") +const newid = require("../../db/newid") const ajv = new Ajv() @@ -9,7 +9,7 @@ exports.save = async function(ctx) { const record = ctx.request.body if (!record._rev && !record._id) { - record._id = uuid.v4().replace(/-/, "") + record._id = newid() } // validation with ajv diff --git a/packages/server/src/db/newid.js b/packages/server/src/db/newid.js new file mode 100644 index 0000000000..6af467480d --- /dev/null +++ b/packages/server/src/db/newid.js @@ -0,0 +1,5 @@ +const { v4 } = require("uuid") + +module.exports = function() { + return v4().replace(/-/g, "") +}