Skip to content

feat: replace getinstancesbybusinesskey with a general getinstances method#106

Draft
Kronprinz03 wants to merge 14 commits into
mainfrom
105-feat-replace-getinstancesbybusinesskey-with-a-general-getinstances-method
Draft

feat: replace getinstancesbybusinesskey with a general getinstances method#106
Kronprinz03 wants to merge 14 commits into
mainfrom
105-feat-replace-getinstancesbybusinesskey-with-a-general-getinstances-method

Conversation

@Kronprinz03
Copy link
Copy Markdown
Contributor

@Kronprinz03 Kronprinz03 commented May 11, 2026

Replace getInstancesByBusinessKey with a General getInstances Method

New Feature / Refactor

♻️ Replaced the narrowly scoped getInstancesByBusinessKey method (which required businessKey as a mandatory parameter and only supported filtering by status) with a more flexible, general-purpose getInstances method. The new method accepts a rich set of optional filter parameters, enabling querying by instance ID, definition, timestamps, text search, pagination, sorting, and more — aligning with the full capabilities of the underlying workflow API.

Changes

  • lib/api/workflow-client.ts: Introduced GetInstancesParams interface with ~17 optional filter fields, added INSTANCES_PARAMS_SKIP_KEYS and INSTANCES_PARAM_KEY_MAP constants for API query building, added the getInstances function, and extended IWorkflowInstanceClient. Also enriched the WorkflowInstance type with definitionVersion, startedAt, completedAt, startedBy, and subject fields.
  • lib/api/local-workflow-store.ts: Implemented getInstances(params) on the local store supporting all filter params (date ranges, text search, pagination, etc.), replacing getInstancesByBusinessKey.
  • lib/api/index.ts: Exported new types and constants (GetInstancesParams, INSTANCES_PARAMS_SKIP_KEYS, INSTANCES_PARAM_KEY_MAP, getInstances).
  • lib/handlers/processService.ts: Renamed handler from getInstancesByBusinessKey to getInstances, switched to GetInstancesParams, removed the mandatory businessKey validation.
  • lib/processImport/csnBuilder.ts: Updated getInstances CSN definition with all new optional params; added id, subject, businessKey, completedAt to ProcessInstance type; fixed startedAt type to Timestamp.
  • srv/BTPProcessService.cds: Replaced getInstancesByBusinessKey function signature with the new getInstances function accepting all optional filter params.
  • srv/BTPProcessService.ts / srv/localProcessService.ts: Updated event handlers to use getInstances with GetInstancesParams.
  • tests/bookshop/srv/annotation-hybrid-service.cds/.ts: Updated action definitions and handler registrations from getInstancesByBusinessKey to getInstances.
  • tests/bookshop/srv/programmatic-service.cds/.ts: Renamed actions and handlers accordingly.
  • tests/bookshop/srv/external/*.cds / tests/hybrid/importedCDS/*.cds: Regenerated CDS files reflecting the new getInstances signature, updated ProcessInstance type with id, completedAt (Timestamp), subject, businessKey.
  • tests/sample/status-management/srv/authors-service.js / books-service.js: Updated calls from getInstancesByBusinessKey(id, statuses) to getInstances({ businessKey, status }).
  • tests/hybrid/annotationApproach.test.ts / programmaticApproach.test.ts: Updated test endpoint paths to use getInstances.
  • tests/bookshop/srv/workflows/*.json: Updated test workflow fixture files with minor JSON schema cleanup.
  • 🔄 Regenerate and Update Summary
PR Bot Information

Version: 1.20.43

  • File Content Strategy: Full file content
  • Event Trigger: pull_request.opened
  • Summary Prompt: Default Prompt
  • LLM: anthropic--claude-4.6-sonnet
  • Output Template: Default Template
  • Correlation ID: 4d21e4c9-9854-4a43-b66b-679149569720

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Choose a reason for hiding this comment

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

The PR is a solid refactor replacing the narrow getInstancesByBusinessKey with a general-purpose getInstances method. The changes are broad and consistent across most files, but there are a few correctness issues: the local store's rootInstanceId/parentInstanceId filters incorrectly match against i.id, the API URL is built with an unconditional trailing ? when no params are provided, status values are not URL-encoded unlike all other query params, and the sample service CDS files are incomplete (missing new ProcessInstance fields and most of the new getInstances parameters) compared to all other updated generated files in the PR.

PR Bot Information

Version: 1.20.43

  • Event Trigger: pull_request.opened
  • Correlation ID: 4d21e4c9-9854-4a43-b66b-679149569720
  • LLM: anthropic--claude-4.6-sonnet
  • File Content Strategy: Full file content

Comment thread lib/api/local-workflow-store.ts Outdated
Comment thread lib/api/workflow-client.ts Outdated
Comment on lines +177 to +178
for (const s of params.status ?? []) {
queryParts.push(`status=${s}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The status values are appended to the query string without encodeURIComponent

All other scalar params are encoded via encodeURIComponent(String(value)), but the status loop appends raw enum values directly. While current WorkflowStatus values are simple ASCII strings, keeping encoding consistent prevents breakage if status values ever change and avoids the inconsistency.

Consider:

for (const s of params.status ?? []) {
  queryParts.push(`status=${encodeURIComponent(s)}`);
}
Suggested change
for (const s of params.status ?? []) {
queryParts.push(`status=${s}`);
for (const s of params.status ?? []) {
queryParts.push(`status=${encodeURIComponent(s)}`);
}

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Comment thread lib/api/workflow-client.ts Outdated
Comment on lines +52 to 61
function getInstances(
businessKey : String,
status : many String,
definitionId : String,
definitionVersion : String,
startedAt : String,
completedAt : String,
startedBy : String,
subject : String
) returns ProcessInstances;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inconsistency: The getInstances function signature in the sample .cds files is missing many parameters present in the main BTPProcessService.cds and the generated hybrid test .cds files

The hybrid-test generated CDS files expose the full parameter set (including id, startedFrom, startedUpTo, completedFrom, completedUpTo, containsText, rootInstanceId, parentInstanceId, top, skip, orderBy, inlinecount), but the sample service CDS files (authorVerificationProcess.cds, bookApprovalProcess.cds) only expose a partial subset (8 params). This means callers using the sample service cannot pass the new filtering, pagination, or ordering params. If these files are regenerated by the import process, they should be consistent; if maintained manually, they need to be brought in line with the full parameter set.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Comment on lines +57 to +60
orderBy?: string | null;
top?: number | null;
skip?: number | null;
inlinecount?: string | null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure if we should 1:1 mirror the wfApi here, I think it makes it more complicated to include those orderBy / top / skip / inlinecount

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean we try to mirror the sbpa workflow api as much as possible, if you think they are to noise I can remove orderBy and inlinecount since they are sbpa specific

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would remove them at least as they, from my POV dont bring any benefit

Comment thread lib/api/local-workflow-store.ts Outdated
if (status) {
const params = req.data as GetInstancesParams;

if (params.status) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we validate status here, but what about other params? Are they not validated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because it is the only thing we know upfront the rest are strings / numbers / dates which we can not validate other then for the type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do those strings have any character limited defined in sbpa?

Comment thread srv/BTPProcessService.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Replace getInstancesByBusinessKey with a general getInstances method

3 participants