Skip to content
New issue

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

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

Already on GitHub? # to your account

Feature Request: Extend modify Method Parameters to Match mingo’s Update API #1375

Open
Karbashevskyi opened this issue Feb 6, 2025 · 2 comments

Comments

@Karbashevskyi
Copy link

Karbashevskyi commented Feb 6, 2025

First of all, I want to sincerely thank you for your amazing work on signalDB! 🙌 This library is incredibly useful, and I really appreciate the effort and dedication you put into maintaining it. Your contribution to the open-source community makes developers’ lives easier, and I truly value that. 🚀


Currently, the modify method in signalDB only accepts two parameters:

function modify<T extends Record<string, any>>(
  item: T,
  modifier: Modifier,
)

However, mingo’s update method supports additional parameters that provide more flexibility when updating documents in IndexedDB:

(
  obj: AnyObject,
  expr: UpdateExpression,
  arrayFilters: AnyObject[] = [],
  condition: AnyObject = {},
  options: UpdateOptions = {}
): string[] => 

Since signalDB already uses mingo, extending the modify method to accept these extra parameters would enable more powerful updates, such as:
• Array filters (arrayFilters) – useful for targeted modifications within arrays
• Update conditions (condition) – allows conditional updates
• Additional options (options) – provides finer control over the update process

Proposed Solution

Modify the modify method in signalDB to support the same parameters as mingo. This would make it fully compatible with mingo’s update API while maintaining backward compatibility.

References
• signalDB modify method: modify.ts
• mingo update method: updater.ts

Benefits
• Provides more flexibility in document updates
• Aligns signalDB with mingo’s update API
• Reduces the need for workarounds when performing complex updates

Maybe solution:

import { UpdateExpression, AnyObject, UpdateOptions, update } from 'mingo';
import type { Modifier } from '../types';

export default function modify<T extends Record<string, any>>(
  item: T,
  modifier: Modifier,
  arrayFilters: AnyObject[] = [],
  condition: AnyObject = {},
  options: UpdateOptions = {}
): T {
  const clonedItem = { ...item };
  update(clonedItem, modifier as UpdateExpression, arrayFilters, condition, options);
  return clonedItem;
}

Thanks!

@maxnowack
Copy link
Owner

@Karbashevskyi thanks for your effort! Do you know what the purpose of condition and options are? I couldn't find anything in the mingo documentation.

@Karbashevskyi
Copy link
Author

@maxnowack

Thanks for your response!

According to the code comments in mingo, condition refers to validation conditions that must be met before performing the update, while options are update options that allow overriding defaults. These parameters are defined in src/updater.ts:98.

That being said, if the documentation is not clear enough to define their intended use cases, we can proceed without them for now. Let me know what you think!

Links:

https://github.com/kofrasa/mingo/blob/9a1c0a28ac6a6a6765c89d82d8d92f7896775fd1/src/updater.ts#L98

https://kofrasa.github.io/mingo/functions/updater.update.html

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants