Skip to content

A local-first personal finance app

Remove redundant UUID wrapper module, update uuid package to 9.x (#1216)

Jed Fox1733179bfbca
diff --git a/.eslintrc.js b/.eslintrc.js
index f83baef0d8..0113177c33 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -18,6 +18,11 @@ const restrictedImportPatterns = [
group: ['*.api', '*.web', '*.electron'],
message: 'Don’t directly reference imports from other platforms',
},
+ {
+ group: ['uuid'],
+ importNames: ['*'],
+ message: "Use `import { v4 as uuidv4 } from 'uuid'` instead",
+ },
];
module.exports = {
diff --git a/packages/api/package.json b/packages/api/package.json
index 06a4a05e67..2e1af2ff0e 100644
--- a/packages/api/package.json
+++ b/packages/api/package.json
@@ -18,9 +18,10 @@
"dependencies": {
"better-sqlite3": "^8.2.0",
"node-fetch": "^2.6.9",
- "uuid": "3.3.2"
+ "uuid": "^9.0.0"
},
"devDependencies": {
+ "@types/uuid": "^9.0.2",
"typescript": "^5.0.2"
}
}
diff --git a/packages/crdt/package.json b/packages/crdt/package.json
index d6dd400c6e..7bc760091d 100644
--- a/packages/crdt/package.json
+++ b/packages/crdt/package.json
@@ -17,10 +17,11 @@
"dependencies": {
"google-protobuf": "^3.12.0-rc.1",
"murmurhash": "^0.0.2",
- "uuid": "3.3.2"
+ "uuid": "^9.0.0"
},
"devDependencies": {
"@types/jest": "^27.5.0",
+ "@types/uuid": "^9.0.2",
"jest": "^27.0.0",
"ts-jest": "^27.0.0",
"ts-protoc-gen": "^0.15.0",
diff --git a/packages/crdt/src/crdt/timestamp.ts b/packages/crdt/src/crdt/timestamp.ts
index 6d431f4381..16a3d4a0cb 100644
--- a/packages/crdt/src/crdt/timestamp.ts
+++ b/packages/crdt/src/crdt/timestamp.ts
@@ -1,5 +1,5 @@
import murmurhash from 'murmurhash';
-import uuid from 'uuid';
+import { v4 as uuidv4 } from 'uuid';
/**
* Hybrid Unique Logical Clock (HULC) timestamp generator
@@ -64,7 +64,7 @@ export function deserializeClock(clock) {
}
export function makeClientId() {
- return uuid.v4().replace(/-/g, '').slice(-16);
+ return uuidv4().replace(/-/g, '').slice(-16);
}
let config = {
diff --git a/packages/desktop-client/package.json b/packages/desktop-client/package.json
index 549ad923d4..fea3f023a8 100644
--- a/packages/desktop-client/package.json
+++ b/packages/desktop-client/package.json
@@ -21,6 +21,7 @@
"@types/react-dom": "^18.2.1",
"@types/react-modal": "^3.16.0",
"@types/react-router-dom": "^5.3.3",
+ "@types/uuid": "^9.0.2",
"@types/webpack-bundle-analyzer": "^4.6.0",
"cross-env": "^7.0.3",
"customize-cra": "^1.0.0",
@@ -51,6 +52,7 @@
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"sass": "^1.63.6",
+ "uuid": "^9.0.0",
"victory": "^36.6.8",
"webpack-bundle-analyzer": "^4.9.0"
},
diff --git a/packages/desktop-client/src/components/accounts/TransactionsTable.test.js b/packages/desktop-client/src/components/accounts/TransactionsTable.test.js
index de3c7911f5..47ca9cb6e5 100644
--- a/packages/desktop-client/src/components/accounts/TransactionsTable.test.js
+++ b/packages/desktop-client/src/components/accounts/TransactionsTable.test.js
@@ -3,6 +3,7 @@ import React, { useState, useEffect } from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { format as formatDate, parse as parseDate } from 'date-fns';
+import { v4 as uuidv4 } from 'uuid';
import {
generateTransaction,
@@ -11,7 +12,6 @@ import {
} from 'loot-core/src/mocks';
import { TestProvider } from 'loot-core/src/mocks/redux';
import { initServer } from 'loot-core/src/platform/client/fetch';
-import * as uuid from 'loot-core/src/platform/uuid';
import {
addSplitTransaction,
realizeTempTransactions,
@@ -772,7 +772,7 @@ describe('Transactions', () => {
// Change the id to simulate a new transaction being added, and
// work with that one. This makes sure that the transaction table
// properly references new data.
- transactions[0] = { ...transactions[0], id: uuid.v4Sync() };
+ transactions[0] = { ...transactions[0], id: uuidv4() };
updateProps({ transactions });
function expectErrorToNotExist(transactions) {
diff --git a/packages/import-ynab4/importer.js b/packages/import-ynab4/importer.js
index e71c960112..c0633e67bb 100644
--- a/packages/import-ynab4/importer.js
+++ b/packages/import-ynab4/importer.js
@@ -7,7 +7,7 @@ import { amountToInteger } from '@actual-app/api/utils';
import AdmZip from 'adm-zip';
import * as d from 'date-fns';
import normalizePathSep from 'slash';
-import uuid from 'uuid';
+import { v4 as uuidv4 } from 'uuid';
// Utils
@@ -160,11 +160,11 @@ async function importTransactions(data, entityIdMap) {
// Go ahead and generate ids for all of the transactions so we can
// reliably resolve transfers
for (let transaction of data.transactions) {
- entityIdMap.set(transaction.entityId, uuid.v4());
+ entityIdMap.set(transaction.entityId, uuidv4());
if (transaction.subTransactions) {
for (let subTransaction of transaction.subTransactions) {
- entityIdMap.set(subTransaction.entityId, uuid.v4());
+ entityIdMap.set(subTransaction.entityId, uuidv4());
}
}
}
diff --git a/packages/import-ynab4/package.json b/packages/import-ynab4/package.json
index 053b48df77..fd4c41a23b 100644
--- a/packages/import-ynab4/package.json
+++ b/packages/import-ynab4/package.json
@@ -21,6 +21,9 @@
"date-fns": "^2.29.3",
"slash": "3.0.0",
"ts-node": "^10.9.1",
- "uuid": "3.3.2"
+ "uuid": "^9.0.0"
+ },
+ "devDependencies": {
+ "@types/uuid": "^9.0.2"
}
}
diff --git a/packages/import-ynab5/importer.js b/packages/import-ynab5/importer.js
index 25a48c7e6c..581f23fc68 100644
--- a/packages/import-ynab5/importer.js
+++ b/packages/import-ynab5/importer.js
@@ -3,7 +3,7 @@
// case and ignore everything else; otherwise we'd be pulling in the
// entire backend bundle from the API
import * as actual from '@actual-app/api/methods';
-import uuid from 'uuid';
+import { v4 as uuidv4 } from 'uuid';
function amountFromYnab(amount) {
// ynabs multiplies amount by 1000 and actual by 100
@@ -162,7 +162,7 @@ async function importTransactions(data, entityIdMap) {
// Go ahead and generate ids for all of the transactions so we can
// reliably resolve transfers
for (let transaction of data.transactions) {
- entityIdMap.set(transaction.id, uuid.v4());
+ entityIdMap.set(transaction.id, uuidv4());
}
await Promise.all(
diff --git a/packages/import-ynab5/package.json b/packages/import-ynab5/package.json
index c686e8d3a5..1e20fd3927 100644
--- a/packages/import-ynab5/package.json
+++ b/packages/import-ynab5/package.json
@@ -19,6 +19,9 @@
"@actual-app/api": "*",
"date-fns": "^2.29.3",
"ts-node": "^10.9.1",
- "uuid": "3.3.2"
+ "uuid": "^9.0.0"
+ },
+ "devDependencies": {
+ "@types/uuid": "^9.0.2"
}
}
diff --git a/packages/loot-core/package.json b/packages/loot-core/package.json
index d32b9df5c9..df5a87b743 100644
--- a/packages/loot-core/package.json
+++ b/packages/loot-core/package.json
@@ -50,6 +50,7 @@
"@types/jest": "^27.5.0",
"@types/jlongster__sql.js": "npm:@types/sql.js@latest",
"@types/pegjs": "^0.10.3",
+ "@types/uuid": "^9.0.2",
"@types/webpack": "^5.28.0",
"@types/webpack-bundle-analyzer": "^4.6.0",
"adm-zip": "^0.5.9",
@@ -73,7 +74,7 @@
"ts-jest": "^27.0.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
- "uuid": "3.3.2",
+ "uuid": "^9.0.0",
"webpack": "^5.86.0",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^5.1.3",
diff --git a/packages/loot-core/src/client/actions/notifications.ts b/packages/loot-core/src/client/actions/notifications.ts
index 86c1a1ccd7..732c744d92 100644
--- a/packages/loot-core/src/client/actions/notifications.ts
+++ b/packages/loot-core/src/client/actions/notifications.ts
@@ -1,4 +1,5 @@
-import * as uuid from '../../platform/uuid';
+import { v4 as uuidv4 } from 'uuid';
+
import * as constants from '../constants';
export function addNotification(notification) {
@@ -6,7 +7,7 @@ export function addNotification(notification) {
type: constants.ADD_NOTIFICATION,
notification: {
...notification,
- id: notification.id || uuid.v4Sync(),
+ id: notification.id || uuidv4(),
},
};
}
diff --git a/packages/loot-core/src/mocks/index.ts b/packages/loot-core/src/mocks/index.ts
index 2d4fcee59a..6d43e6a248 100644
--- a/packages/loot-core/src/mocks/index.ts
+++ b/packages/loot-core/src/mocks/index.ts
@@ -1,10 +1,11 @@
-import * as uuid from '../platform/uuid';
+import { v4 as uuidv4 } from 'uuid';
+
import * as monthUtils from '../shared/months';
import type { TransactionEntity } from '../types/models';
export function generateAccount(name, isConnected, offbudget) {
return {
- id: uuid.v4Sync(),
+ id: uuidv4(),
name,
balance_current: isConnected ? Math.floor(Math.random() * 100000) : null,
bank: isConnected ? Math.floor(Math.random() * 10000) : null,
@@ -18,7 +19,7 @@ export function generateAccount(name, isConnected, offbudget) {
let sortOrder = 1;
export function generateCategory(name, group, isIncome = false) {
return {
- id: uuid.v4Sync(),
+ id: uuidv4(),
name: name,
cat_group: group,
is_income: isIncome ? 1 : 0,
@@ -29,7 +30,7 @@ export function generateCategory(name, group, isIncome = false) {
let groupSortOrder = 1;
export function generateCategoryGroup(name, isIncome = false) {
return {
- id: uuid.v4Sync(),
+ id: uuidv4(),
name: name,
is_income: isIncome ? 1 : 0,
sort_order: groupSortOrder++,
@@ -50,7 +51,7 @@ export function generateCategoryGroups(definition) {
}
function _generateTransaction(data): TransactionEntity {
- const id = data.id || uuid.v4Sync();
+ const id = data.id || uuidv4();
return {
id: id,
amount: data.amount || Math.floor(Math.random() * 10000 - 7000),
@@ -77,7 +78,7 @@ export function generateTransaction(data, splitAmount?, showError = false) {
result.push(
{
- id: parent.id + '/' + uuid.v4Sync(),
+ id: parent.id + '/' + uuidv4(),
amount: trans.amount - splitAmount,
account: parent.account,
date: parent.date,
@@ -86,7 +87,7 @@ export function generateTransaction(data, splitAmount?, showError = false) {
isChild: true,
},
{
- id: parent.id + '/' + uuid.v4Sync(),
+ id: parent.id + '/' + uuidv4(),
amount: splitAmount,
account: parent.account,
date: parent.date,
diff --git a/packages/loot-core/src/mocks/plaid.ts b/packages/loot-core/src/mocks/plaid.ts
index 2e783d1852..c192d6bf38 100644
--- a/packages/loot-core/src/mocks/plaid.ts
+++ b/packages/loot-core/src/mocks/plaid.ts
@@ -1,8 +1,8 @@
-import * as uuid from '../platform/uuid';
+import { v4 as uuidv4 } from 'uuid';
export function generateAccount(balance) {
return {
- account_id: uuid.v4Sync(),
+ account_id: uuidv4(),
balances: {
available: balance,
current: balance,
@@ -52,7 +52,7 @@ export function generateTransaction(
},
pending: pending,
pending_transaction_id: null,
- transaction_id: uuid.v4Sync(),
+ transaction_id: uuidv4(),
transaction_type: 'special',
};
}
diff --git a/packages/loot-core/src/platform/client/fetch/index.browser.ts b/packages/loot-core/src/platform/client/fetch/index.browser.ts
index 98122be9f4..8280b84931 100644
--- a/packages/loot-core/src/platform/client/fetch/index.browser.ts
+++ b/packages/loot-core/src/platform/client/fetch/index.browser.ts
@@ -1,5 +1,6 @@
+import { v4 as uuidv4 } from 'uuid';
+
import { captureException, captureBreadcrumb } from '../../exceptions';
-import * as uuid from '../../uuid';
import * as undo from '../undo';
import type * as T from '.';
@@ -147,21 +148,21 @@ export const send: T.Send = function (
{ catchErrors = false } = {},
) {
return new Promise((resolve, reject) => {
- uuid.v4().then(id => {
- replyHandlers.set(id, { resolve, reject });
- let message = {
- id,
- name,
- args,
- undoTag: undo.snapshot(),
- catchErrors,
- };
- if (messageQueue) {
- messageQueue.push(message);
- } else {
- globalWorker.postMessage(message);
- }
- });
+ let id = uuidv4();
+
+ replyHandlers.set(id, { resolve, reject });
+ let message = {
+ id,
+ name,
+ args,
+ undoTag: undo.snapshot(),
+ catchErrors,
+ };
+ if (messageQueue) {
+ messageQueue.push(message);
+ } else {
+ globalWorker.postMessage(message);
+ }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any;
};
diff --git a/packages/loot-core/src/platform/client/fetch/index.web.ts b/packages/loot-core/src/platform/client/fetch/index.web.ts
index e9427c7c7a..2040d8f0d0 100644
--- a/packages/loot-core/src/platform/client/fetch/index.web.ts
+++ b/packages/loot-core/src/platform/client/fetch/index.web.ts
@@ -1,4 +1,5 @@
-import * as uuid from '../../uuid';
+import { v4 as uuidv4 } from 'uuid';
+
import * as undo from '../undo';
import type * as T from '.';
@@ -85,31 +86,30 @@ export const send: T.Send = function (
{ catchErrors = false } = {},
) {
return new Promise((resolve, reject) => {
- uuid.v4().then(id => {
- replyHandlers.set(id, { resolve, reject });
-
- if (socketClient) {
- socketClient.send(
- JSON.stringify({
- id,
- name,
- args,
- undoTag: undo.snapshot(),
- catchErrors: !!catchErrors,
- }),
- );
- } else {
- messageQueue.push(
- JSON.stringify({
- id,
- name,
- args,
- undoTag: undo.snapshot(),
- catchErrors,
- }),
- );
- }
- });
+ let id = uuidv4();
+ replyHandlers.set(id, { resolve, reject });
+
+ if (socketClient) {
+ socketClient.send(
+ JSON.stringify({
+ id,
+ name,
+ args,
+ undoTag: undo.snapshot(),
+ catchErrors: !!catchErrors,
+ }),
+ );
+ } else {
+ messageQueue.push(
+ JSON.stringify({
+ id,
+ name,
+ args,
+ undoTag: undo.snapshot(),
+ catchErrors,
+ }),
+ );
+ }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any;
};
diff --git a/packages/loot-core/src/platform/client/undo/index.web.ts b/packages/loot-core/src/platform/client/undo/index.web.ts
index 0ccb5c6ccf..3718a85c33 100644
--- a/packages/loot-core/src/platform/client/undo/index.web.ts
+++ b/packages/loot-core/src/platform/client/undo/index.web.ts
@@ -1,4 +1,4 @@
-import * as uuid from '../../uuid';
+import { v4 as uuidv4 } from 'uuid';
import type * as T from '.';
@@ -15,7 +15,7 @@ let currentUndoState: T.UndoState = {
export const setUndoState: T.SetUndoState = function (name, value) {
currentUndoState[name] = value;
- currentUndoState.id = uuid.v4Sync();
+ currentUndoState.id = uuidv4();
};
export const getUndoState: T.GetUndoState = function (name) {
@@ -27,7 +27,7 @@ export const getTaggedState: T.GetTaggedState = function (id) {
};
export const snapshot: T.Snapshot = function () {
- let tagged = { ...currentUndoState, id: uuid.v4Sync() };
+ let tagged = { ...currentUndoState, id: uuidv4() };
UNDO_STATE_MRU.unshift(tagged);
UNDO_STATE_MRU = UNDO_STATE_MRU.slice(0, HISTORY_SIZE);
return tagged.id;
diff --git a/packages/loot-core/src/platform/uuid/index.d.ts b/packages/loot-core/src/platform/uuid/index.d.ts
deleted file mode 100644
index 13fb979028..0000000000
--- a/packages/loot-core/src/platform/uuid/index.d.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export function v4(): Promise<string>;
-export type V4 = typeof v4;
-
-export function v4Sync(): string;
-export type V4Sync = typeof v4Sync;
diff --git a/packages/loot-core/src/platform/uuid/index.electron.ts b/packages/loot-core/src/platform/uuid/index.electron.ts
deleted file mode 100644
index 84708652b3..0000000000
--- a/packages/loot-core/src/platform/uuid/index.electron.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import uuid from 'uuid';
-
-import type * as T from '.';
-
-export const v4: T.V4 = function () {
- return Promise.resolve(uuid.v4());
-};
-
-export const v4Sync: T.V4Sync = function () {
- return uuid.v4();
-};
diff --git a/packages/loot-core/src/platform/uuid/index.web.ts b/packages/loot-core/src/platform/uuid/index.web.ts
deleted file mode 100644
index 84708652b3..0000000000
--- a/packages/loot-core/src/platform/uuid/index.web.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import uuid from 'uuid';
-
-import type * as T from '.';
-
-export const v4: T.V4 = function () {
- return Promise.resolve(uuid.v4());
-};
-
-export const v4Sync: T.V4Sync = function () {
- return uuid.v4();
-};
diff --git a/packages/loot-core/src/server/accounts/link.ts b/packages/loot-core/src/server/accounts/link.ts
index 5815e89b4e..e7a663af2f 100644
--- a/packages/loot-core/src/server/accounts/link.ts
+++ b/packages/loot-core/src/server/accounts/link.ts
@@ -1,5 +1,6 @@
+import { v4 as uuidv4 } from 'uuid';
+
import * as asyncStorage from '../../platform/server/asyncStorage';
-import * as uuid from '../../platform/uuid';
import { amountToInteger } from '../../shared/util';
import * as db from '../db';
import { runMutator } from '../mutators';
@@ -18,7 +19,7 @@ export async function handoffPublicToken(institution, publicToken) {
throw new Error('Invalid institution object');
}
- let id = uuid.v4Sync();
+ let id = uuidv4();
// Make sure to generate an access token first before inserting it
// into our local database in case it fails
@@ -51,7 +52,7 @@ export async function findOrCreateBank(institution, requisitionId) {
}
const bankData = {
- id: uuid.v4Sync(),
+ id: uuidv4(),
bank_id: requisitionId,
name: institution.name,
};
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index 7cf272d1f7..4b72d0f638 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -1,7 +1,7 @@
import * as dateFns from 'date-fns';
+import { v4 as uuidv4 } from 'uuid';
import * as asyncStorage from '../../platform/server/asyncStorage';
-import * as uuid from '../../platform/uuid';
import * as monthUtils from '../../shared/months';
import {
makeChild as makeChildTransaction,
@@ -229,7 +229,7 @@ async function resolvePayee(trans, payeeName, payeesToCreate) {
return payee.id;
} else {
// Otherwise we're going to create a new one
- let newPayee = { id: uuid.v4Sync(), name: payeeName };
+ let newPayee = { id: uuidv4(), name: payeeName };
payeesToCreate.set(payeeName.toLowerCase(), newPayee);
return newPayee.id;
}
@@ -521,7 +521,7 @@ export async function reconcileNordigenTransactions(acctId, transactions) {
// Insert a new transaction
let finalTransaction = {
...trans,
- id: uuid.v4Sync(),
+ id: uuidv4(),
category: trans.category || null,
cleared: trans.cleared != null ? trans.cleared : true,
};
@@ -666,7 +666,7 @@ export async function reconcileTransactions(acctId, transactions) {
// Insert a new transaction
let finalTransaction = {
...trans,
- id: uuid.v4Sync(),
+ id: uuidv4(),
category: trans.category || null,
cleared: trans.cleared != null ? trans.cleared : true,
};
@@ -708,7 +708,7 @@ export async function addTransactions(
trans = runRules(trans);
let finalTransaction = {
- id: uuid.v4Sync(),
+ id: uuidv4(),
...trans,
account: acctId,
cleared: trans.cleared != null ? trans.cleared : true,
diff --git a/packages/loot-core/src/server/aql/exec.test.ts b/packages/loot-core/src/server/aql/exec.test.ts
index 1bcbbbdd03..f4fc8cf8d5 100644
--- a/packages/loot-core/src/server/aql/exec.test.ts
+++ b/packages/loot-core/src/server/aql/exec.test.ts
@@ -1,4 +1,5 @@
-import * as uuid from '../../platform/uuid';
+import { v4 as uuidv4 } from 'uuid';
+
import query from '../../shared/query';
import { makeChild } from '../../shared/transactions';
import * as db from '../db';
@@ -37,14 +38,14 @@ async function insertTransactions(repeatTimes = 1) {
});
let parent = {
- id: uuid.v4Sync(),
+ id: uuidv4(),
account: 'acct',
date: '2020-01-04',
amount: -100,
is_parent: true,
};
let parent2 = {
- id: uuid.v4Sync(),
+ id: uuidv4(),
account: 'acct',
date: '2020-01-01',
amount: -89,
@@ -115,7 +116,7 @@ describe('runQuery', () => {
});
it('provides named parameters and converts types', async () => {
- let transId = uuid.v4Sync();
+ let transId = uuidv4();
await db.insertTransaction({
id: transId,
account: 'acct',
@@ -196,7 +197,7 @@ describe('runQuery', () => {
});
it('parameters have the correct order', async () => {
- let transId = uuid.v4Sync();
+ let transId = uuidv4();
await db.insertTransaction({
id: transId,
account: 'acct',
diff --git a/packages/loot-core/src/server/backups.ts b/packages/loot-core/src/server/backups.ts
index 69afbd4c7d..713e2b3fe5 100644
--- a/packages/loot-core/src/server/backups.ts
+++ b/packages/loot-core/src/server/backups.ts
@@ -1,9 +1,9 @@
import * as dateFns from 'date-fns';
+import { v4 as uuidv4 } from 'uuid';
import * as connection from '../platform/server/connection';
import * as fs from '../platform/server/fs';
import * as sqlite from '../platform/server/sqlite';
-import * as uuid from '../platform/uuid';
import * as monthUtils from '../shared/months';
import * as cloudStorage from './cloud-storage';
@@ -111,7 +111,7 @@ export async function makeBackup(id: string) {
await fs.removeFile(fs.join(fs.getBudgetDir(id), LATEST_BACKUP_FILENAME));
}
- let backupId = `${uuid.v4Sync()}.sqlite`;
+ let backupId = `${uuidv4()}.sqlite`;
let backupPath = fs.join(budgetDir, 'backups', backupId);
if (!(await fs.exists(fs.join(budgetDir, 'backups')))) {
diff --git a/packages/loot-core/src/server/cloud-storage.ts b/packages/loot-core/src/server/cloud-storage.ts
index 7d61118b5e..cf6deab1f2 100644
--- a/packages/loot-core/src/server/cloud-storage.ts
+++ b/packages/loot-core/src/server/cloud-storage.ts
@@ -1,10 +1,10 @@
import AdmZip from 'adm-zip';
+import { v4 as uuidv4 } from 'uuid';
import * as asyncStorage from '../platform/server/asyncStorage';
import { fetch } from '../platform/server/fetch';
import * as fs from '../platform/server/fs';
import * as sqlite from '../platform/server/sqlite';
-import * as uuid from '../platform/uuid';
import * as monthUtils from '../shared/months';
import * as encryption from './encryption';
@@ -257,7 +257,7 @@ export async function upload() {
}
if (!cloudFileId) {
- cloudFileId = uuid.v4Sync();
+ cloudFileId = uuidv4();
}
let res;
diff --git a/packages/loot-core/src/server/db/index.ts b/packages/loot-core/src/server/db/index.ts
index ca27accf63..ef7bc22d5c 100644
--- a/packages/loot-core/src/server/db/index.ts
+++ b/packages/loot-core/src/server/db/index.ts
@@ -7,10 +7,10 @@ import {
Timestamp,
} from '@actual-app/crdt';
import LRU from 'lru-cache';
+import { v4 as uuidv4 } from 'uuid';
import * as fs from '../../platform/server/fs';
import * as sqlite from '../../platform/server/sqlite';
-import * as uuid from '../../platform/uuid';
import { groupById } from '../../shared/util';
import {
schema,
@@ -196,7 +196,7 @@ export async function update(table, params) {
export async function insertWithUUID(table, row) {
if (!row.id) {
- row = { ...row, id: uuid.v4Sync() };
+ row = { ...row, id: uuidv4() };
}
await insert(table, row);
@@ -255,7 +255,7 @@ export function insertWithSchema(table, row) {
// Even though `insertWithUUID` does this, we need to do it here so
// the schema validation passes
if (!row.id) {
- row = { ...row, id: uuid.v4Sync() };
+ row = { ...row, id: uuidv4() };
}
return insertWithUUID(
diff --git a/packages/loot-core/src/server/encryption.ts b/packages/loot-core/src/server/encryption.ts
index 159421aa43..9ca45ee4f3 100644
--- a/packages/loot-core/src/server/encryption.ts
+++ b/packages/loot-core/src/server/encryption.ts
@@ -1,4 +1,4 @@
-import * as uuid from '../platform/uuid';
+import { v4 as uuidv4 } from 'uuid';
import * as internals from './encryption-internals';
@@ -11,7 +11,7 @@ class Key {
value;
constructor({ id }) {
- this.id = id || uuid.v4Sync();
+ this.id = id || uuidv4();
}
async createFromPassword({ password, salt }) {
diff --git a/packages/loot-core/src/server/main.ts b/packages/loot-core/src/server/main.ts
index 1cf496e8e8..79715587a4 100644
--- a/packages/loot-core/src/server/main.ts
+++ b/packages/loot-core/src/server/main.ts
@@ -3,6 +3,7 @@ import * as injectAPI from '@actual-app/api/injected';
import * as CRDT from '@actual-app/crdt';
import * as YNAB4 from '@actual-app/import-ynab4/importer';
import * as YNAB5 from '@actual-app/import-ynab5/importer';
+import { v4 as uuidv4 } from 'uuid';
import { createTestBudget } from '../mocks/budget';
import { captureException, captureBreadcrumb } from '../platform/exceptions';
@@ -11,7 +12,6 @@ import * as connection from '../platform/server/connection';
import * as fs from '../platform/server/fs';
import logger from '../platform/server/log';
import * as sqlite from '../platform/server/sqlite';
-import * as uuid from '../platform/uuid';
import { isNonProductionEnvironment } from '../shared/environment';
import * as monthUtils from '../shared/months';
import q, { Query } from '../shared/query';
@@ -789,7 +789,7 @@ handlers['nordigen-accounts-link'] = async function ({
bank: bank.id,
});
} else {
- id = uuid.v4Sync();
+ id = uuidv4();
await db.insertWithUUID('accounts', {
id,
account_id: account.account_id,
@@ -958,7 +958,7 @@ handlers['account-close'] = mutator(async function ({
);
await handlers['transaction-add']({
- id: uuid.v4Sync(),
+ id: uuidv4(),
payee: payeeId,
amount: -balance,
account: id,
@@ -1538,7 +1538,7 @@ handlers['key-make'] = async function ({ password }) {
}
let salt = encryption.randomBytes(32).toString('base64');
- let id = uuid.v4Sync();
+ let id = uuidv4();
let key = await encryption.createKey({ id, password, salt });
// Load the key
diff --git a/packages/loot-core/src/server/migrate/migrations.ts b/packages/loot-core/src/server/migrate/migrations.ts
index e87794f079..ca229ca682 100644
--- a/packages/loot-core/src/server/migrate/migrations.ts
+++ b/packages/loot-core/src/server/migrate/migrations.ts
@@ -1,10 +1,11 @@
// We have to bundle in JS migrations manually to avoid having to `eval`
// them which doesn't play well with CSP. There isn't great, and eventually
// we can remove this migration.
+import { v4 as uuidv4 } from 'uuid';
+
import m1632571489012 from '../../../migrations/1632571489012_remove_cache';
import * as fs from '../../platform/server/fs';
import * as sqlite from '../../platform/server/sqlite';
-import * as uuid from '../../platform/uuid';
let MIGRATIONS_DIR = fs.migrationsPath;
@@ -81,7 +82,7 @@ async function applyJavaScript(db, id) {
}
let run = javascriptMigrations[id];
- return run(dbInterface, () => uuid.v4Sync());
+ return run(dbInterface, () => uuidv4());
}
async function applySql(db, sql) {
diff --git a/packages/loot-core/src/server/schedules/app.ts b/packages/loot-core/src/server/schedules/app.ts
index fded914635..16df0c1c66 100644
--- a/packages/loot-core/src/server/schedules/app.ts
+++ b/packages/loot-core/src/server/schedules/app.ts
@@ -1,9 +1,9 @@
import * as d from 'date-fns';
import deepEqual from 'deep-equal';
+import { v4 as uuidv4 } from 'uuid';
import { captureBreadcrumb } from '../../platform/exceptions';
import * as connection from '../../platform/server/connection';
-import * as uuid from '../../platform/uuid';
import { dayFromDate, currentDay, parseDate } from '../../shared/months';
import q from '../../shared/query';
import {
@@ -205,7 +205,7 @@ export async function createSchedule({
schedule = null,
conditions = [],
} = {}) {
- let scheduleId = (schedule && schedule.id) || uuid.v4Sync();
+ let scheduleId = (schedule && schedule.id) || uuidv4();
let { date: dateCond } = extractScheduleConds(conditions);
if (dateCond == null) {
diff --git a/packages/loot-core/src/server/schedules/find-schedules.ts b/packages/loot-core/src/server/schedules/find-schedules.ts
index 31e6ece6e9..3eb2efe8ab 100644
--- a/packages/loot-core/src/server/schedules/find-schedules.ts
+++ b/packages/loot-core/src/server/schedules/find-schedules.ts
@@ -1,6 +1,6 @@
import * as d from 'date-fns';
+import { v4 as uuidv4 } from 'uuid';
-import * as uuid from '../../platform/uuid';
import { dayFromDate, parseDate } from '../../shared/months';
import q from '../../shared/query';
import { getApproxNumberThreshold } from '../../shared/rules';
@@ -369,7 +369,7 @@ export async function findSchedules() {
// Convert to schedule and return it
return {
- id: uuid.v4Sync(),
+ id: uuidv4(),
account: winner.account,
payee: winner.payee,
date: winner.date,
diff --git a/packages/loot-core/src/server/util/budget-name.ts b/packages/loot-core/src/server/util/budget-name.ts
index a6c428cb72..b6e9bfe783 100644
--- a/packages/loot-core/src/server/util/budget-name.ts
+++ b/packages/loot-core/src/server/util/budget-name.ts
@@ -1,5 +1,6 @@
+import { v4 as uuidv4 } from 'uuid';
+
import * as fs from '../../platform/server/fs';
-import * as uuid from '../../platform/uuid';
export async function uniqueFileName(existingFiles) {
let initialName = 'My Finances';
@@ -17,8 +18,7 @@ export async function uniqueFileName(existingFiles) {
}
export async function idFromFileName(name) {
- let id =
- name.replace(/( |[^A-Za-z0-9])/g, '-') + '-' + uuid.v4Sync().slice(0, 7);
+ let id = name.replace(/( |[^A-Za-z0-9])/g, '-') + '-' + uuidv4().slice(0, 7);
// Make sure the id is unique. There's a chance one could already
// exist (although very unlikely now that we append unique
diff --git a/packages/loot-core/src/shared/transactions.test.ts b/packages/loot-core/src/shared/transactions.test.ts
index b448ba28ce..7aca05f272 100644
--- a/packages/loot-core/src/shared/transactions.test.ts
+++ b/packages/loot-core/src/shared/transactions.test.ts
@@ -1,4 +1,4 @@
-import * as uuid from '../platform/uuid';
+import { v4 as uuidv4 } from 'uuid';
import {
splitTransaction,
@@ -14,7 +14,7 @@ import {
function makeTransaction(data) {
return {
- id: uuid.v4Sync(),
+ id: uuidv4(),
amount: 2422,
date: '2020-01-05',
account: 'acct1',
diff --git a/packages/loot-core/src/shared/transactions.ts b/packages/loot-core/src/shared/transactions.ts
index a1b2e425c8..ac5675b5a8 100644
--- a/packages/loot-core/src/shared/transactions.ts
+++ b/packages/loot-core/src/shared/transactions.ts
@@ -1,4 +1,4 @@
-import * as uuid from '../platform/uuid';
+import { v4 as uuidv4 } from 'uuid';
import { last, diffItems, applyChanges } from './util';
@@ -28,7 +28,7 @@ export function makeChild(parent, data) {
amount: 0,
...data,
payee: data.payee || parent.payee,
- id: data.id ? data.id : prefix + uuid.v4Sync(),
+ id: data.id ? data.id : prefix + uuidv4(),
account: parent.account,
date: parent.date,
cleared: parent.cleared != null ? parent.cleared : null,
@@ -242,14 +242,14 @@ export function splitTransaction(transactions, id) {
export function realizeTempTransactions(transactions) {
let parent = transactions.find(t => !t.is_child);
- parent = { ...parent, id: uuid.v4Sync() };
+ parent = { ...parent, id: uuidv4() };
let children = transactions.filter(t => t.is_child);
return [
parent,
...children.map(child => ({
...child,
- id: uuid.v4Sync(),
+ id: uuidv4(),
parent_id: parent.id,
})),
];
diff --git a/upcoming-release-notes/1216.md b/upcoming-release-notes/1216.md
new file mode 100644
index 0000000000..ab1a47bbe3
--- /dev/null
+++ b/upcoming-release-notes/1216.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [j-f1]
+---
+
+Remove redundant UUID wrapper module, update `uuid` package to 9.x
diff --git a/yarn.lock b/yarn.lock
index 5759cfa18b..e6c4176bbf 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -16,10 +16,11 @@ __metadata:
version: 0.0.0-use.local
resolution: "@actual-app/api@workspace:packages/api"
dependencies:
+ "@types/uuid": ^9.0.2
better-sqlite3: ^8.2.0
node-fetch: ^2.6.9
typescript: ^5.0.2
- uuid: 3.3.2
+ uuid: ^9.0.0
languageName: unknown
linkType: soft
@@ -28,13 +29,14 @@ __metadata:
resolution: "@actual-app/crdt@workspace:packages/crdt"
dependencies:
"@types/jest": ^27.5.0
+ "@types/uuid": ^9.0.2
google-protobuf: ^3.12.0-rc.1
jest: ^27.0.0
murmurhash: ^0.0.2
ts-jest: ^27.0.0
ts-protoc-gen: ^0.15.0
typescript: ^5.0.2
- uuid: 3.3.2
+ uuid: ^9.0.0
languageName: unknown
linkType: soft
@@ -43,11 +45,12 @@ __metadata:
resolution: "@actual-app/import-ynab4@workspace:packages/import-ynab4"
dependencies:
"@actual-app/api": "*"
+ "@types/uuid": ^9.0.2
adm-zip: ^0.5.9
date-fns: ^2.29.3
slash: 3.0.0
ts-node: ^10.9.1
- uuid: 3.3.2
+ uuid: ^9.0.0
bin:
import-ynab4: ./index.js
languageName: unknown
@@ -58,9 +61,10 @@ __metadata:
resolution: "@actual-app/import-ynab5@workspace:packages/import-ynab5"
dependencies:
"@actual-app/api": "*"
+ "@types/uuid": ^9.0.2
date-fns: ^2.29.3
ts-node: ^10.9.1
- uuid: 3.3.2
+ uuid: ^9.0.0
bin:
import-ynab5: ./index.js
languageName: unknown
@@ -85,6 +89,7 @@ __metadata:
"@types/react-dom": ^18.2.1
"@types/react-modal": ^3.16.0
"@types/react-router-dom": ^5.3.3
+ "@types/uuid": ^9.0.2
"@types/webpack-bundle-analyzer": ^4.6.0
cross-env: ^7.0.3
customize-cra: ^1.0.0
@@ -115,6 +120,7 @@ __metadata:
redux: ^4.0.5
redux-thunk: ^2.3.0
sass: ^1.63.6
+ uuid: ^9.0.0
victory: ^36.6.8
webpack-bundle-analyzer: ^4.9.0
languageName: unknown
@@ -4471,6 +4477,13 @@ __metadata:
languageName: node
linkType: hard
+"@types/uuid@npm:^9.0.2":
+ version: 9.0.2
+ resolution: "@types/uuid@npm:9.0.2"
+ checksum: 1754bcf3444e1e3aeadd6e774fc328eb53bc956665e2e8fb6ec127aa8e1f43d9a224c3d22a9a6233dca8dd81a12dc7fed4d84b8876dd5ec82d40f574f7ff8b68
+ languageName: node
+ linkType: hard
+
"@types/verror@npm:^1.10.3":
version: 1.10.6
resolution: "@types/verror@npm:1.10.6"
@@ -12344,6 +12357,7 @@ __metadata:
"@types/jest": ^27.5.0
"@types/jlongster__sql.js": "npm:@types/sql.js@latest"
"@types/pegjs": ^0.10.3
+ "@types/uuid": ^9.0.2
"@types/webpack": ^5.28.0
"@types/webpack-bundle-analyzer": ^4.6.0
absurd-sql: 0.0.53
@@ -12382,7 +12396,7 @@ __metadata:
ts-jest: ^27.0.0
ts-node: ^10.7.0
typescript: ^4.6.4
- uuid: 3.3.2
+ uuid: ^9.0.0
webpack: ^5.86.0
webpack-bundle-analyzer: ^4.9.0
webpack-cli: ^5.1.3
@@ -17984,15 +17998,6 @@ __metadata:
languageName: node
linkType: hard
-"uuid@npm:3.3.2":
- version: 3.3.2
- resolution: "uuid@npm:3.3.2"
- bin:
- uuid: ./bin/uuid
- checksum: 8793629d2799f500aeea9fcd0aec6c4e9fbcc4d62ed42159ad96be345c3fffac1bbf61a23e18e2782600884fee05e6d4012ce4b70d0037c8e987533ae6a77870
- languageName: node
- linkType: hard
-
"uuid@npm:^8.3.2":
version: 8.3.2
resolution: "uuid@npm:8.3.2"
@@ -18002,6 +18007,15 @@ __metadata:
languageName: node
linkType: hard
+"uuid@npm:^9.0.0":
+ version: 9.0.0
+ resolution: "uuid@npm:9.0.0"
+ bin:
+ uuid: dist/bin/uuid
+ checksum: 8dd2c83c43ddc7e1c71e36b60aea40030a6505139af6bee0f382ebcd1a56f6cd3028f7f06ffb07f8cf6ced320b76aea275284b224b002b289f89fe89c389b028
+ languageName: node
+ linkType: hard
+
"v8-compile-cache-lib@npm:^3.0.1":
version: 3.0.1
resolution: "v8-compile-cache-lib@npm:3.0.1"