-
Notifications
You must be signed in to change notification settings - Fork 111
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
Feature/multiple loaders and cli #547
Feature/multiple loaders and cli #547
Conversation
added ability to pass an optional custom response body formatter
Feature/custom response body
changed generated file default path
fixed tests that become broken accidently
fixed most current tests
made fixes to make it work properly removed watch mode because I don't like even idea to generate it in runtime
…uces a breaking changes
…ders Feature/support multiple loaders
…ders renamed base methods for validations to make code cleaner
…ders updated version
improvements for tests and imports did a lot of manual testing for the cli with different situations for json
…on the fly anymore
…s_client Feature/proper generate types client
…s_client updated version and added changing permissions for cli file after build
… and prevent names duplications
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.
as long as no tests break fine with me. For the cli feature, @toonvanstrijp will have to give his confirmation
…s_and_cli # Conflicts: # package.json # samples/dto-validation/src/app.module.ts # samples/simple/src/app.controller.ts # samples/simple/src/app.module.ts # src/i18n.constants.ts # src/i18n.module.ts # src/loaders/i18n.abstract-file.loader.ts # src/loaders/i18n.json.loader.ts # src/loaders/i18n.loader.ts # src/loaders/i18n.yaml.loader.ts # src/resolvers/header.resolver.ts # src/resolvers/query.resolver.ts # src/services/i18n.service.ts # src/utils/merge.ts # src/utils/typescript.ts # tsconfig.json
…conds just for safety and play with debounce
…th github workflow
# Conflicts: # tests/i18n-fastify.e2e.spec.ts
I did fix all issues with pipelines. @toonvanstrijp let me know when you can take a look and approve the work, so I can do the documentation part, and because of the breaking change it probably will be 11.0.0? |
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.
@vsamofal awesome work so far! I'm really happy and grateful for the effort you're putting in. I think with a few more things to discuss we could make an awesome V11 release that's going to take this library in the right direction!
@@ -0,0 +1,17 @@ | |||
#!/usr/bin/env node |
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.
@vsamofal I'm a very big fan of this feature! One of the early versions of nestjs-i18n had this feature implemented. But I think we could even improve on this a little bit more.
What if we move the I18nOptions
to a file (e.g. i18n.ts) just like how mikro-orm does it too. That way we make the i18n-cli use that config, but also let the nestjs module use that config.
This would end up with a better workflow and configuration.
this.events.pipe(switchMap(() => this.parseTranslations())), | ||
); | ||
} | ||
async load(): Promise<I18nTranslation> { |
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.
I think we might need to be careful with removing the Observable
as a return type. If we change it to a promise instead, it won't be possible to have translation be loaded in real time or be pushed be some other event. This means you would need to call refresh yourself whenever is needed. What are your thoughts on this @rubiin ?
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.
I agree. Promise and Observables work differently. Observables are mostly preferred way of working with streams i.e series of data unlike promises which would mostly resolve a single value and be done
loaderOptions: { | ||
path: path.join(__dirname, '/i18n/'), | ||
}, | ||
loaders: [ |
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.
Is it still possible to use dependency injection in the loader? Now if you loader for example used your mikro-orm connection it won't be possible to inject this. Maybe we need to rethink the loader options a bit. Since if we're going to make breaking changes for a V11, we can make a few more to change this we don't particularly like now.
…lder and removed auto generation
# Conflicts: # package-lock.json # package.json # src/i18n.context.ts # src/i18n.module.ts # src/index.ts # src/loaders/i18n.abstract-file.loader.ts # src/loaders/i18n.json.loader.ts # src/loaders/i18n.yaml.loader.ts # src/services/i18n.service.ts
@rubiin @toonvanstrijp Hi guys, when you have time can you take a look |
Will be cherry picking some commits that are no breaking |
please approve this pr, we need these changes |
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"postbuild": "chmod +x ./dist/cli.js", |
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.
why do we need to set execution mode?
return newPath.startsWith('./') ? newPath.slice(2) : newPath; | ||
} | ||
|
||
function sanitizePaths(paths: string[]) { |
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.
does it work for win system?
|
||
function sanitizePath(path: string) { | ||
// adding trailing slash | ||
const newPath = path.endsWith('/') ? path : `${path}/`; |
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.
can we use node:path.parse function?
catch(exception: I18nValidationException, host: ArgumentsHost) { | ||
const i18n = I18nContext.current(); | ||
|
||
const errors = formatI18nErrors(exception.errors ?? [], i18n.service, { | ||
lang: i18n.lang, | ||
}); | ||
|
||
const normalizedErrors = this.normalizeValidationErrors(errors); | ||
|
||
switch (host.getType() as string) { | ||
case 'http': |
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.
should we process the 'rpc' context type?
@@ -0,0 +1,80 @@ | |||
import fs from "fs" | |||
import path from "path" | |||
import {pathToFileURL} from "url" |
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.
here it's not formatted, but
I'm not sure that it was needed to re-format all to another code-style, definitely imports, order of import and private\public methods
(if it's prettier fix - ok)
@@ -6,11 +6,14 @@ | |||
"emitDecoratorMetadata": true, | |||
"experimentalDecorators": true, | |||
"skipLibCheck": true, | |||
"importHelpers": false, |
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.
why you turn off importHelpers?
# Conflicts: # package-lock.json # samples/dto-validation/pnpm-lock.yaml # samples/simple/pnpm-lock.yaml # src/filters/i18n-validation-exception.filter.ts # src/i18n.context.ts # src/i18n.module.ts # tests/app/controllers/hello.controller.ts # tests/app/examples/example.functions.ts # tsconfig.json
Lets break the changes into different PR . Would be easier to review and rollout considering the breaking changes. |
closed in favor of #628 |
Description
I implemented 3 features, one small, and two that actually broke existing functionality.
I also need to update the documentation if these changes are ok to do, also it's a breaking change probably, version 11 makes more sense.
I don't expect this pr to be merged, but more to have a conversation about all of these changes.
Thanks
Linked Issues
Additional context
the easiest way to test a client is to
npm install @saas-buildkit/nestjs-i18n
nestjs-i18n -h