Skip to content

feat: nested key paths#59

Open
tada5hi wants to merge 4 commits intostalniy:masterfrom
tada5hi:mongo-type
Open

feat: nested key paths#59
tada5hi wants to merge 4 commits intostalniy:masterfrom
tada5hi:mongo-type

Conversation

@tada5hi
Copy link
Copy Markdown

@tada5hi tada5hi commented Sep 4, 2025

resolves #57

Besides implementing nested key paths, i also dumped the version of typescript from 3.x to 5.x (was 2 versions behind), as well replacing babel with swc, which lead to much faster builds.
And for some reason you didn't link the packages between each other, which lead to pnpm pulling @swc/core from the npm registry instead of refering to the local workspace.

@stalniy
Copy link
Copy Markdown
Owner

stalniy commented Sep 5, 2025

Hey,

Thank you for the PR. Libraries are not linked via pnpm workspaces because semantic-release doesn't allow to use pnpm instead of npm for publishing packages. but anyway pnpm links them together if the version matches what is specified in package.json of other package

@stalniy
Copy link
Copy Markdown
Owner

stalniy commented Sep 5, 2025

though, I'd like PR to be feature centric, so if it's about nested paths, then it should not contain all other infra related things. This should be done separately. I will do some updates to master

@stalniy
Copy link
Copy Markdown
Owner

stalniy commented Sep 5, 2025

I want to migrate to release-it but right now don't have free time to some major refactorings and testing

@tada5hi
Copy link
Copy Markdown
Author

tada5hi commented Sep 5, 2025

Hey,

Thank you for the PR. Libraries are not linked via pnpm workspaces because semantic-release doesn't allow to use pnpm instead of npm for publishing packages. but anyway pnpm links them together if the version matches what is specified in package.json of other package

you are very welcome! ☺️

@tada5hi
Copy link
Copy Markdown
Author

tada5hi commented Sep 5, 2025

though, I'd like PR to be feature centric, so if it's about nested paths, then it should not contain all other infra related things. This should be done separately. I will do some updates to master

Totally understand that and also wasn't my intension. I can revert the changes to the package.json regarding the version specification (workspace:*).
But the dump of Typescript was required, due the "string literal type" feature of typescript which wasn't supported with TS 3.x.

@tada5hi
Copy link
Copy Markdown
Author

tada5hi commented Sep 5, 2025

I want to migrate to release-it but right now don't have free time to some major refactorings and testing

I can also highly recommend https://github.com/googleapis/release-please and i have good experiences with it so far. Besides it works very well with monorepos.
I can create a pull request for that if you want?

Besides, I would also be happy to help you in general with maintaining the project, if you need help.

@stalniy
Copy link
Copy Markdown
Owner

stalniy commented Sep 5, 2025

I want to migrate to release-it but right now don't have free time to some major refactorings and testing

I can also highly recommend https://github.com/googleapis/release-please and i have good experiences with it so far. Besides it works very well with monorepos. I can create a pull request for that if you want?

Besides, I would also be happy to help you in general with maintaining the project, if you need help.

would be awesome. Thanks for the support! I just briefly looked into release-please but yeah the main idea is to have a release PR instead of releasing on every merge because then I can see the version change clearly and adjust it if it's wrong.

@stalniy
Copy link
Copy Markdown
Owner

stalniy commented Sep 5, 2025

I'd also replace @swc/core with esbuild because esbuild also fast and this project doesn't use decorators, so there is no much sense to use @swc/core. Moreover, by using esbuild we could get rid of rollup and other stuff. Distributing es5* versions also doesn't make sense nowadays

@stalniy
Copy link
Copy Markdown
Owner

stalniy commented Sep 5, 2025

or maybe tsup -> https://github.com/egoist/tsup

@stalniy
Copy link
Copy Markdown
Owner

stalniy commented Sep 5, 2025

I'll make a push to your branch to resolve conflicts after my changes in master. I upgraded eslint/typescript separately, so this change can be cleaner

Comment on lines -3 to -13
type ArgsExceptLast<F extends (...args: any[]) => any> =
F extends (a: any, c: any) => any
? Parameters<(condition: Condition) => 0>
: F extends (a: any, b: any, c: any) => any
? Parameters<(condition: Condition, value: Parameters<F>[1]) => 0>
: Parameters<(
condition: Condition,
value: Parameters<F>[1],
options: Parameters<F>[2],
...args: unknown[]
) => 0>;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

in the past, ts didn't support labels for tuples and in order to transfer proper argument names into inferred functions, I needed to use this construct Parameters<(condition: Condition, value: Parameters<F>[1]) => 0> because then this tuple preserverd the names in the function. without this it was just (arg_0: condition, arg_1: ....)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't know how it works right now for this specific case but I'll revert this change to ensure it works as expected

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

ah, ok, just checked. now it works even with spread operator

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

no, actually not. Because this changes the inferred types. interpret function should have Condition as the first argument but after this change it infers it from the passed function which is wrong because sometimes it's CompoundCondition

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ArgsExceptLast is now a generic type for an arbitairy function and just strips the last Argument.
This should still work, because createInterpreter enforces that the passed function must extend AnyInterpreter, which is required to have Condition as the first argument.

Copy link
Copy Markdown
Owner

@stalniy stalniy Sep 6, 2025

Choose a reason for hiding this comment

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

CompoundCondition extends Condition, so technically it satisfies the restriction but then it doesn’t allow to pass Condition to interpret nested conditions. It forces to pass CompoundCondition.

And as a result inside ConpoubdCondition, interpret helper cannot be used to evaluate nested conditions because ts fails

@@ -50,29 +45,29 @@ export function createInterpreter<T extends AnyInterpreter, U extends {} = {}>(

switch (options ? options.numberOfArguments : 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I also don't think you have to make this differentiation by the number of arguments, whith my approach it works with arbitairy numer of arguments.
So an interpreter can have any amount of arguments and the context is still passed as last argument.

const interpret = ((condition : Condition, ...params: any[]) => {
    const interpreterName = getInterpreterName(condition, options);
    const interpretOperator = getInterpreter(interpreters, interpreterName);
    return interpretOperator.apply(null, [condition, ...params, defaultContext]);// eslint-disable-line @typescript-eslint/no-use-before-define
  }) as unknown as InterpretationContext<T>['interpret'];

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yeah, this is micro optimization. So we have a function with static amount of arguments. This is not used by end users anyway, so it's just for internal library composition

Comment on lines -3 to -13
type ArgsExceptLast<F extends (...args: any[]) => any> =
F extends (a: any, c: any) => any
? Parameters<(condition: Condition) => 0>
: F extends (a: any, b: any, c: any) => any
? Parameters<(condition: Condition, value: Parameters<F>[1]) => 0>
: Parameters<(
condition: Condition,
value: Parameters<F>[1],
options: Parameters<F>[2],
...args: unknown[]
) => 0>;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ArgsExceptLast is now a generic type for an arbitairy function and just strips the last Argument.
This should still work, because createInterpreter enforces that the passed function must extend AnyInterpreter, which is required to have Condition as the first argument.

@tada5hi
Copy link
Copy Markdown
Author

tada5hi commented Sep 5, 2025

I would also be happy to help you with the maintaining of the project.

I'd also replace @swc/core with esbuild because esbuild also fast and this project doesn't use decorators, so there is no much sense to use @swc/core. Moreover, by using esbuild we could get rid of rollup and other stuff. Distributing es5* versions also doesn't make sense nowadays

I think you can achieve the same thing with both tools. Swc can also be used without rollup.
So in the end it depends on which tool you like more.

@tada5hi
Copy link
Copy Markdown
Author

tada5hi commented Sep 5, 2025

I want to migrate to release-it but right now don't have free time to some major refactorings and testing

I can also highly recommend https://github.com/googleapis/release-please and i have good experiences with it so far. Besides it works very well with monorepos. I can create a pull request for that if you want?
Besides, I would also be happy to help you in general with maintaining the project, if you need help.

would be awesome. Thanks for the support! I just briefly looked into release-please but yeah the main idea is to have a release PR instead of releasing on every merge because then I can see the version change clearly and adjust it if it's wrong.

great, than i will create a pull request for release-please.
And let me know, if you need help maintaining the project. I'm willing to help :)

@J3m5
Copy link
Copy Markdown
Contributor

J3m5 commented Sep 5, 2025

or maybe tsup -> https://github.com/egoist/tsup

Just my 2 cents, you should try tsdown, the successor of tsup, based on rolldown
https://tsdown.dev/

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.

Feature: Nested Object Conditions

3 participants