Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper types to runHandler #2136

Merged
merged 3 commits into from
Jan 9, 2024
Merged

Conversation

twk3
Copy link
Contributor

@twk3 twk3 commented Dec 29, 2023

Summary

  • Args and return values from runHandler should now work within loot core
  • Updated some of the handler types to be more accurate

Split from #2053 to start preparing to bring types to the API.

Verify

Can be verified by going to one of the places that runHandlers is called, like the main.test.ts or the mocks/budget.ts and trying to put in some incorrect args to a handler that is strongly typed.

Like the following where a test: "this will error" was added:

await runHandler(handlers['schedule/create'], {
        schedule: {
          name: 'Phone bills',
          posts_transaction: false,
          test: "this will error",
        },
        conditions: [
          {
            op: 'is',
            field: 'payee',
            value: payees.find(item => item.name === 'Dominion Power').id,
          },
          {
            op: 'is',
            field: 'account',
            value: account.id,
          },
          {
            op: 'is',
            field: 'date',
            value: {
              start: monthUtils.currentDay(),
              frequency: 'monthly',
              patterns: [],
              skipWeekend: false,
              weekendSolveMode: 'after',
            },
          },
          { op: 'isapprox', field: 'amount', value: -12000 },
        ],
      });

Then either yarn typecheck or your IDE with flag the error.

@trafico-bot trafico-bot bot added the 🚧 WIP label Dec 29, 2023
Copy link

netlify bot commented Dec 29, 2023

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit a44f01a
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/659db310b9fa2900083669e2
😎 Deploy Preview https://deploy-preview-2136.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Dec 29, 2023

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
15 3.08 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/main.js 1.43 MB 0%
static/js/665.chunk.js 824.28 kB 0%
static/media/Inter-italic.var.woff2 239.29 kB 0%
static/media/Inter-roman.var.woff2 221.86 kB 0%
static/js/231.chunk.js 117.38 kB 0%
static/js/wide-components.chunk.js 112.37 kB 0%
static/js/reports.chunk.js 77.81 kB 0%
static/js/narrow-components.chunk.js 42.42 kB 0%
static/js/553.chunk.js 13.14 kB 0%
static/js/473.chunk.js 13 kB 0%
static/js/resize-observer-polyfill.chunk.js 8.88 kB 0%
static/css/main.css 7.41 kB 0%
asset-manifest.json 1.92 kB 0%
index.html 1.66 kB 0%
static/media/browser-server.js 911 B 0%

Copy link
Contributor

github-actions bot commented Dec 29, 2023

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
2 2.23 MB → 2.23 MB (+11 B) +0.00%
Changeset
File Δ Size
packages/loot-core/src/server/main.ts 📈 +23 B (+0.04%) 63.65 kB → 63.67 kB
packages/loot-core/src/mocks/budget.ts 📈 +4 B (+0.01%) 28.49 kB → 28.5 kB
packages/loot-core/src/platform/server/connection/index.web.ts 📉 -59 B (-1.62%) 3.55 kB → 3.49 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.24 MB → 1.24 MB (+11 B) +0.00%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
xfo.xfo.kcab.worker.js 1014.45 kB 0%

@twk3 twk3 changed the title [WIP] Add proper types to runHandler Add proper types to runHandler Dec 29, 2023
Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for hardening our types

packages/loot-core/src/types/server-handlers.d.ts Outdated Show resolved Hide resolved
@twk3 twk3 requested a review from MatissJanis December 30, 2023 23:24
@twk3
Copy link
Contributor Author

twk3 commented Dec 31, 2023

@MatissJanis this is ready for another review

MatissJanis
MatissJanis previously approved these changes Jan 6, 2024
Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

MatissJanis
MatissJanis previously approved these changes Jan 7, 2024
twk3 added 2 commits January 9, 2024 11:37
- Args and return values from runHandler should now work within loot core
- Updated some of the handler types to be more accurate
@twk3 twk3 merged commit b330991 into actualbudget:master Jan 9, 2024
19 checks passed
@trafico-bot trafico-bot bot added ✨ Merged Pull Request has been merged successfully and removed ✅ Approved labels Jan 9, 2024
@twk3 twk3 deleted the typescript-run-handler branch January 9, 2024 21:05
FlorianLang06 pushed a commit to FlorianLang06/actual that referenced this pull request Mar 7, 2024
* Add proper types to runHandler

- Args and return values from runHandler should now work within loot core
- Updated some of the handler types to be more accurate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Merged Pull Request has been merged successfully
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants