diff --git a/package-lock.json b/package-lock.json index 4729cffea763..c59874d96f02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -94,7 +94,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "git+https://github.com/Expensify/react-native-onyx#cd778b55e419bf09ecf377b1e3ac013b7758434d", + "react-native-onyx": "2.0.23", "react-native-pager-view": "6.2.2", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", @@ -39474,10 +39474,9 @@ } }, "node_modules/react-native-onyx": { - "version": "2.0.10", - "resolved": "git+ssh://git@github.com/Expensify/react-native-onyx.git#cd778b55e419bf09ecf377b1e3ac013b7758434d", - "integrity": "sha512-0ky9ISCNhuch0onIkeu/XFhVHoLp7gFwg6Q5TZYt1Wfmu/48Z9fjJxKxw5PRLfNBtwDQZQWKYFAf/CIoBxnmZw==", - "license": "MIT", + "version": "2.0.23", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.23.tgz", + "integrity": "sha512-A0SuipCwAswl8+hBlr9tNPTBdxixKBJkcdP8YpgUC072/4Kcfvv0pfpfQOHoeCR/bP2wvDagpdN3VtebRfoVMg==", "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", diff --git a/package.json b/package.json index 61e3557bbe67..dd4ee4da63ce 100644 --- a/package.json +++ b/package.json @@ -145,7 +145,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "git+https://github.com/Expensify/react-native-onyx#cd778b55e419bf09ecf377b1e3ac013b7758434d", + "react-native-onyx": "2.0.23", "react-native-pager-view": "6.2.2", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", diff --git a/src/libs/Console/index.ts b/src/libs/Console/index.ts index 423e1037a605..f03d33674bde 100644 --- a/src/libs/Console/index.ts +++ b/src/libs/Console/index.ts @@ -24,7 +24,7 @@ Onyx.connect({ const originalConsoleLog = console.log; /* List of patterns to ignore in logs. "logs" key always needs to be ignored because otherwise it will cause infinite loop */ -const logPatternsToIgnore = [`merge() called for key: ${ONYXKEYS.LOGS}`]; +const logPatternsToIgnore = [`merge called for key: ${ONYXKEYS.LOGS}`]; /** * Check if the log should be attached to the console diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index a93efb8cbff5..3487f05b9c05 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -40,7 +40,7 @@ function getAuthenticateErrorMessage(response: Response): keyof TranslationFlatO * Method used to get an error object with microsecond as the key. * @param error - error key or message to be saved */ -function getMicroSecondOnyxError(error: string | null, isTranslated = false, errorKey?: number): Errors { +function getMicroSecondOnyxError(error: string, isTranslated = false, errorKey?: number): Errors { return {[errorKey ?? DateUtils.getMicroseconds()]: error && [error, {isTranslated}]}; } diff --git a/src/libs/actions/ActiveClients.ts b/src/libs/actions/ActiveClients.ts index e59fdc14410e..a2ea87d10cd2 100644 --- a/src/libs/actions/ActiveClients.ts +++ b/src/libs/actions/ActiveClients.ts @@ -1,7 +1,7 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; -function setActiveClients(activeClients: string[]): Promise { +function setActiveClients(activeClients: string[]): Promise { return Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients); } diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index bb20b2b686ab..64527319c35a 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -56,7 +56,7 @@ type PersonalAddress = { requestorAddressZipCode?: string; }; -function clearPlaid(): Promise { +function clearPlaid(): Promise { Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, ''); Onyx.set(ONYXKEYS.PLAID_CURRENT_EVENT, null); return Onyx.set(ONYXKEYS.PLAID_DATA, PlaidDataProps.plaidDataDefaultProps); diff --git a/src/libs/actions/CachedPDFPaths/types.ts b/src/libs/actions/CachedPDFPaths/types.ts index 98b768c4645e..728759daaa98 100644 --- a/src/libs/actions/CachedPDFPaths/types.ts +++ b/src/libs/actions/CachedPDFPaths/types.ts @@ -1,4 +1,4 @@ -type Add = (id: string, path: string) => Promise; +type Add = (id: string, path: string) => Promise; type Clear = (path: string) => Promise; type ClearAll = () => void; type ClearByKey = (id: string) => void; diff --git a/src/libs/actions/Download.ts b/src/libs/actions/Download.ts index 6eb3b1f05b4b..e82744aa5d02 100644 --- a/src/libs/actions/Download.ts +++ b/src/libs/actions/Download.ts @@ -4,7 +4,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; /** * Set whether an attachment is being downloaded so that a spinner can be shown. */ -function setDownload(sourceID: string, isDownloading: boolean): Promise { +function setDownload(sourceID: string, isDownloading: boolean): Promise { return Onyx.merge(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {isDownloading}); } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 761ae02ea4c6..41952080d869 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -778,7 +778,7 @@ function buildOnyxDataForMoneyRequest( errors: getReceiptError(transaction.receipt, transaction.filename || transaction.receipt?.filename, isScanRequest, errorKey), }, [iouAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError(null), + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), }, } : { @@ -2507,7 +2507,7 @@ function createSplitsAndOnyxData( key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${splitChatReport.reportID}`, value: { [splitIOUReportAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError(null), + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), }, }, }, @@ -4319,7 +4319,7 @@ function getSendMoneyParams( key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, value: { [optimisticIOUReportAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError(null), + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), }, }, }, diff --git a/src/libs/actions/OnyxUpdates.ts b/src/libs/actions/OnyxUpdates.ts index ab26ad330b6f..e093ce9a964b 100644 --- a/src/libs/actions/OnyxUpdates.ts +++ b/src/libs/actions/OnyxUpdates.ts @@ -1,4 +1,4 @@ -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {Merge} from 'type-fest'; import Log from '@libs/Log'; @@ -27,7 +27,7 @@ function applyHTTPSOnyxUpdates(request: Request, response: Response) { console.debug('[OnyxUpdateManager] Applying https update'); // For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in // the UI. See https://github.com/Expensify/App/issues/12775 for more info. - const updateHandler = request?.data?.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update; + const updateHandler: (updates: OnyxUpdate[]) => Promise = request?.data?.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update; // First apply any onyx data updates that are being sent back from the API. We wait for this to complete and then // apply successData or failureData. This ensures that we do not update any pending, loading, or other UI states contained diff --git a/src/libs/actions/ReimbursementAccount/index.ts b/src/libs/actions/ReimbursementAccount/index.ts index 57d785c5d1c9..62e5f8454cbd 100644 --- a/src/libs/actions/ReimbursementAccount/index.ts +++ b/src/libs/actions/ReimbursementAccount/index.ts @@ -13,7 +13,7 @@ export {setBankAccountFormValidationErrors, resetReimbursementAccount} from './e * - CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL to ask them to enter their accountNumber and routingNumber * - CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID to ask them to login to their bank via Plaid */ -function setBankAccountSubStep(subStep: BankAccountSubStep | null): Promise { +function setBankAccountSubStep(subStep: BankAccountSubStep | null): Promise { return Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: {subStep}}); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index a27f92ef8f57..7d3e70c2842e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1084,7 +1084,7 @@ function saveReportCommentNumberOfLines(reportID: string, numberOfLines: number) } /** Immediate indication whether the report has a draft comment. */ -function setReportWithDraft(reportID: string, hasDraft: boolean): Promise { +function setReportWithDraft(reportID: string, hasDraft: boolean): Promise { return Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {hasDraft}); } diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 123614f2e0bb..9ddaca686e95 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -107,7 +107,7 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp } } -function removeWaypoint(transaction: OnyxEntry, currentIndex: string, isDraft?: boolean): Promise { +function removeWaypoint(transaction: OnyxEntry, currentIndex: string, isDraft?: boolean): Promise { // Index comes from the route params and is a string const index = Number(currentIndex); const existingWaypoints = transaction?.comment?.waypoints ?? {}; @@ -234,7 +234,7 @@ function getRoute(transactionID: string, waypoints: WaypointCollection, isDraft: * @param waypoints - An object containing all the waypoints * which will replace the existing ones. */ -function updateWaypoints(transactionID: string, waypoints: WaypointCollection, isDraft = false): Promise { +function updateWaypoints(transactionID: string, waypoints: WaypointCollection, isDraft = false): Promise { return Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, { comment: { waypoints, diff --git a/src/libs/migrateOnyx.ts b/src/libs/migrateOnyx.ts index e8c0b2bf3e10..d827d9936fd1 100644 --- a/src/libs/migrateOnyx.ts +++ b/src/libs/migrateOnyx.ts @@ -6,11 +6,11 @@ import RemoveEmptyReportActionsDrafts from './migrations/RemoveEmptyReportAction import RenameReceiptFilename from './migrations/RenameReceiptFilename'; import TransactionBackupsToCollection from './migrations/TransactionBackupsToCollection'; -export default function (): Promise { +export default function () { const startTime = Date.now(); Log.info('[Migrate Onyx] start'); - return new Promise((resolve) => { + return new Promise((resolve) => { // Add all migrations to an array so they are executed in order const migrationPromises = [ CheckForPreviousReportActionID, @@ -25,7 +25,7 @@ export default function (): Promise { // previous promise to finish before moving onto the next one. /* eslint-disable arrow-body-style */ migrationPromises - .reduce((previousPromise, migrationPromise) => { + .reduce>((previousPromise, migrationPromise) => { return previousPromise.then(() => { return migrationPromise(); }); diff --git a/src/libs/migrations/CheckForPreviousReportActionID.ts b/src/libs/migrations/CheckForPreviousReportActionID.ts index d97bd87f0a2a..7e4bbe9ffb3e 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.ts +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -21,7 +21,7 @@ function getReportActionsFromOnyx(): Promise { +export default function (): Promise { return getReportActionsFromOnyx().then((allReportActions) => { if (Object.keys(allReportActions ?? {}).length === 0) { Log.info(`[Migrate Onyx] Skipped migration CheckForPreviousReportActionID because there were no reportActions`); diff --git a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts index c8ef72ca15e7..193fdfe5f1eb 100644 --- a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts +++ b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts @@ -14,7 +14,7 @@ type ReportActionsDraftsKey = `${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFT * After: reportActionsDrafts_reportID: {[reportActionID]: value} */ export default function () { - return new Promise((resolve) => { + return new Promise((resolve) => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS, waitForCollectionCallback: true, diff --git a/src/setup/index.ts b/src/setup/index.ts index 581dbd28056f..3cfc0e55eae8 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -1,7 +1,6 @@ import {I18nManager} from 'react-native'; import Onyx from 'react-native-onyx'; import intlPolyfill from '@libs/IntlPolyfill'; -import * as Metrics from '@libs/Metrics'; import * as Device from '@userActions/Device'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -29,7 +28,6 @@ export default function () { // Increase the cached key count so that the app works more consistently for accounts with large numbers of reports maxCachedKeysCount: 20000, safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], - captureMetrics: Metrics.canCaptureOnyxMetrics(), initialKeyStates: { // Clear any loading and error messages so they do not appear on app startup [ONYXKEYS.SESSION]: {loading: false}, diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 2ce72a58aead..caae8a055aa9 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -397,7 +397,6 @@ describe('actions/IOU', () => { new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, - waitForCollectionCallback: true, callback: (transaction) => { Onyx.disconnect(connectionID); expect(transaction?.pendingAction).toBeFalsy(); @@ -2640,7 +2639,6 @@ describe('actions/IOU', () => { await new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT}${thread.reportID}`, - waitForCollectionCallback: true, callback: (report) => { Onyx.disconnect(connectionID); expect(report).toBeTruthy(); @@ -2697,7 +2695,6 @@ describe('actions/IOU', () => { await new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT}${thread.reportID}`, - waitForCollectionCallback: true, callback: (report) => { Onyx.disconnect(connectionID); expect(report).toBeTruthy(); diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index dfb8ae81d104..c673d39cd414 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -1,5 +1,5 @@ import Onyx from 'react-native-onyx'; -import type {OnyxCollection} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; import * as Policy from '@src/libs/actions/Policy'; @@ -41,10 +41,9 @@ describe('actions/Policy', () => { Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID); await waitForBatchedUpdates(); - let policy: OnyxCollection = await new Promise((resolve) => { + let policy: OnyxEntry | OnyxCollection = await new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - waitForCollectionCallback: true, callback: (workspace) => { Onyx.disconnect(connectionID); resolve(workspace); @@ -61,10 +60,9 @@ describe('actions/Policy', () => { expect(policy?.isPolicyExpenseChatEnabled).toBe(true); expect(policy?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - const policyMembers: OnyxCollection = await new Promise((resolve) => { + const policyMembers: OnyxEntry = await new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`, - waitForCollectionCallback: true, callback: (members) => { Onyx.disconnect(connectionID); resolve(members); diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index 5f0bb65cc3ab..a926d0589e80 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -1963,7 +1963,6 @@ describe('ReportActionsUtils', () => { new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, - waitForCollectionCallback: true, callback: () => { Onyx.disconnect(connectionID); const res = ReportActionsUtils.getLastVisibleAction(report.reportID); diff --git a/tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts b/tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts index 862f3281b2b8..084fce5d5c95 100644 --- a/tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts +++ b/tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts @@ -1,4 +1,5 @@ import type Onyx from 'react-native-onyx'; +import type {Writable} from 'type-fest'; import waitForBatchedUpdates from './waitForBatchedUpdates'; /** @@ -9,7 +10,7 @@ import waitForBatchedUpdates from './waitForBatchedUpdates'; * This is a convinience function, which wraps the onyxInstance's * functions, to for the promises to resolve. */ -function wrapOnyxWithWaitForBatchedUpdates(onyxInstance: typeof Onyx) { +function wrapOnyxWithWaitForBatchedUpdates(onyxInstance: Writable) { const multiSetImpl = onyxInstance.multiSet; // eslint-disable-next-line no-param-reassign onyxInstance.multiSet = (...args) => multiSetImpl(...args).then((result) => waitForBatchedUpdates().then(() => result));