Skip to content

Conversation

@Aryan-Shrivastva
Copy link

AppData.build() - Modified to defer index creation when fields don't exist yet.
AppData.resolvePendingIndices() - New method to resolve deferred indices after plugins run.
App.onModulesBuilt() - Updated to call resolvePendingIndices() after plugin schemas are merged.

@cameronapak
Copy link
Contributor

cameronapak commented Dec 30, 2025

update: Yes, yes it does!


Hey Aryan, thanks for your contribution!

Does this fix #325?

@Aryan-Shrivastva
Copy link
Author

I had created a test case file that was verifying the fix . I think it should have fix the #325 issue but if any error shows it, do tell me

@cameronapak
Copy link
Contributor

praise: this approach looks like it'll work

thought: I'm worries that no longer using transformObject in when getting the indicies may accidentally be removing some functionality that was intended. From my overview glancing review of the PR, I cannot confirm if it is or not.

Here's the transformObject function declaration:

export function transformObject<T extends Record<string, any>, U>(
   object: T,
   transform: (value: T[keyof T], key: keyof T) => U | undefined,
): { [K in keyof T]: U } {
   const result = {} as { [K in keyof T]: U };
   for (const [key, value] of Object.entries(object) as [keyof T, T[keyof T]][]) {
      const t = transform(value, key);
      if (typeof t !== "undefined") {
         result[key] = t;
      }
   }
   return result;
}
export const objectTransform = transformObject;

@Aryan-Shrivastva
Copy link
Author

Well i can update the code to use transformObject instead of Object.entries() to preserve the original pattern.

@cameronapak
Copy link
Contributor

Well i can update the code to use transformObject instead of Object.entries() to preserve the original pattern.

Let's do that, because I think that may give it higher chances of being merged in by using that existing pattern

I appreciate you working on this!

@Aryan-Shrivastva
Copy link
Author

Ok changed to the original transformObject. Hope this works!

@cameronapak
Copy link
Contributor

looks good to me! I'll now defer to Dennis for final review

He's on holiday rest at the time of posting this

@Aryan-Shrivastva
Copy link
Author

Yeah sure! Thanks, I'll hop on to another issue in the mean time.!

@dswbx
Copy link
Contributor

dswbx commented Jan 9, 2026

hey @Aryan-Shrivastva, thanks a lot for taking the time to tackle this. Your approach works, and looks generally good. However, I'm a bit afraid of keeping this maintained, also considering that it currently only solves the issue on the timestamps plugin. Consequently, we would add something like this for relations, e.g. when a plugin adds a new entity.

Plugins should be self-contained as much as possible to reduce the surface of error, and prevent headaches in the future. Generally I see 2 ways of solving a situation like this:

  1. add a property to the plugin for the em callback function to customize indexes and relations
  2. add a property to the plugin to tell it what it should do

The first one is not really ideal, as this means your schema is spread (you add your schema in the config prop of the app). That being said, I think option 2 is more straightforward, and so I created this proposal for you @cameronapak and @Aryan-Shrivastva to review: https://github.com/bknd-io/bknd/pull/332/files

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.

3 participants