-
Notifications
You must be signed in to change notification settings - Fork 68
1040 patch leftover #3715
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
1040 patch leftover #3715
Conversation
WalkthroughThe changes introduce a new optional Changes
Sequence Diagram(s)sequenceDiagram
participant DocumentStatus as calculateDocumentConversionStatus
participant Consolidated as recreateConsolidated
participant ResourceDiff as createResourceDiffBundles
DocumentStatus->>Consolidated: recreateConsolidated({patient, context, conversionType, isDq, requestId})
Consolidated->>ResourceDiff: createResourceDiffBundles({patient, context, conversionType, isDq, requestId})
ResourceDiff->>ResourceDiff: Use requestId if provided, else generate new UUID
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
|
Ref: ENG-47 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/shared/src/domain/job/types.ts (1)
6-10
: Confirm downstream impact of shrinkingJobEntryStatus
to only “failed” | “successful”All references th 10000 at previously expected
"waiting"
/"processing"
entry-level states will now fail to compile or, if using string literals dynamically, misbehave at runtime.
Please double-check:
- Migration scripts / DB constraints
- API payload validators (e.g., Zod, Joi, io-ts)
- Analytics dashboards expecting the old states
If those paths are already refactored, consider mirroring the approach used in
job-status.ts
for maintainability:const jobEntryStatus = ["failed", "successful"] as const; export type JobEntryStatus = typeof jobEntryStatus[number]; export function isValidJobEntryStatus( status: string ): status is JobEntryStatus { return (jobEntryStatus as readonly string[]).includes(status as JobEntryStatus); }This avoids hard-coding literals in multiple places.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite
📒 Files selected for processing (3)
packages/api/src/external/ehr/create-resource-diff-bundles.ts
(3 hunks)packages/shared/src/domain/job/job-status.ts
(1 hunks)packages/shared/src/domain/job/types.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/api/src/external/ehr/create-resource-diff-bundles.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.ts`: - Use the Onion Pattern to organize a package's code in layers - Try to use immutable code and avoid sharing state across different functions, objects, and systems - Try...
**/*.ts
: - Use the Onion Pattern to organize a package's code in layers
- Try to use immutable code and avoid sharing state across different functions, objects, and systems
- Try to build code that's idempotent whenever possible
- Prefer functional programming style functions: small, deterministic, 1 input, 1 output
- Minimize coupling / dependencies
- Avoid modifying objects received as parameter
- Only add comments to code to explain why something was done, not how it works
- Naming
- classes, enums:
PascalCase
- constants, variables, functions:
camelCase
- file names:
kebab-case
- table and column names:
snake_case
- Use meaningful names, so whoever is reading the code understands what it means
- Don’t use negative names, like
notEnabled
, preferisDisabled
- For numeric values, if the type doesn’t convey the unit, add the unit to the name
- Typescript
- Use types
- Prefer
const
instead oflet
- Avoid
any
and casting fromany
to other types- Type predicates: only applicable to narrow down the type, not to force a complete type conversion
- Prefer deconstructing parameters for functions instead of multiple parameters that might be of
the same type- Don’t use
null
inside the app, only on code interacting with external interfaces/services,
like DB and HTTP; convert toundefined
before sending inwards into the code- Use
async/await
instead of.then()
- Use the strict equality operator
===
, don’t use abstract equality operator==
- When calling a Promise-returning function asynchronously (i.e., not awaiting), use
.catch()
to
handle errors (seeprocessAsyncError
andemptyFunction
depending on the case)- Date and Time
- Always use
buildDayjs()
to createdayjs
instances- Prefer
dayjs.duration(...)
to create duration consts and keep them asduration
- Prefer Nullish Coalesce (??) than the OR operator (||) to provide a default value
- Avoid creating arrow functions
- Use truthy syntax instead of
in
- i.e.,if (data.link)
notif ('link' in data)
- Error handling
- Pass the original error as the new one’s
cause
so the stack trace is persisted- Error messages should have a static message - add dynamic data to MetriportError's
additionalInfo
prop- Avoid sending multiple events to Sentry for a single error
- Global constants and variables
- Move literals to constants declared after imports when possible (avoid magic numbers)
- Avoid shared, global objects
- Avoid using
console.log
andconsole.error
in packages other than utils, infra and shared,
and try to useout().log
instead- Avoid multi-line logs
- don't send objects as a second parameter to
console.log()
orout().log()
- don't create multi-line strings when using
JSON.stringify()
- Use
eslint
to enforce code style- Use
prettier
to format code- max column length is 100 chars
- multi-line comments use
/** */
- scripts: top-level comments go after the import
packages/shared/src/domain/job/job-status.ts
packages/shared/src/domain/job/types.ts
export function isValidJobStatus(status: string): status is JobStatus { | ||
return ( | ||
status === "waiting" || | ||
status === "processing" || | ||
status === "successful" || | ||
status === "failed" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
“successful” is not a valid JobStatus
– type guard currently lies
JobStatus
is declared as the union "waiting" | "processing" | "completed" | "failed"
, yet the new isValidJobStatus()
returns true
for "successful"
.
This introduces two serious problems:
- The type-predicate now claims
"successful"
satisfiesJobStatus
, which will cause a TS error (or, if--suppressImplicitAnyIndexErrors
is on, silently unsound typing). - Runtime callers will believe
"successful"
is allowed and may persist this value, breaking every consumer that expects only the four canonical statuses (e.g.isJobDone
, DB enums, analytics).
Patch the guard (and preferably DRY it up) like so:
-export function isValidJobStatus(status: string): status is JobStatus {
- return (
- status === "waiting" ||
- status === "processing" ||
- status === "successful" ||
- status === "failed"
- );
-}
+export function isValidJobStatus(status: string): status is JobStatus {
+ // keep implementation in sync with `jobStatus` source-of-truth
+ return (jobStatus as readonly string[]).includes(status as JobStatus);
+}
This fixes the immediate bug and ensures future edits to jobStatus
automatically propagate.
(If "successful"
really is a new status, add it to jobStatus
, update isJobDone
, database enums, etc. in the same PR.)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function isValidJobStatus(status: string): status is JobStatus { | |
return ( | |
status === "waiting" || | |
status === "processing" || | |
status === "successful" || | |
status === "failed" | |
); | |
export function isValidJobStatus(status: string): status is JobStatus { | |
// keep implementation in sync with `jobStatus` source-of-truth | |
return (jobStatus as readonly string[]).includes(status as JobStatus); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomasyopes Great! Thank you for implementing the fix. This will ensure the type guard correctly aligns with the defined job statuses.
Ref: ENG-47 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
|
|
Issues:
Description
Release Plan
Summary by CodeRabbit
New Features
Chores
Bug Fixes
Refactor