ægteemil
ægteemil
Explore posts from servers
NNuxt
Created by ægteemil on 11/22/2024 in #❓・help
Testing with i18n and vitest
Hey. I have a simple component that uses $t for translations. I'm trying to write a simple test, but it's failing.
describe('UserSignInForm', () => {
it('renders', async () => {
const component = await mountSuspended(UserSignInForm);
expect(component.html()).toMatchSnapshot();
});
});
describe('UserSignInForm', () => {
it('renders', async () => {
const component = await mountSuspended(UserSignInForm);
expect(component.html()).toMatchSnapshot();
});
});
I've tried a few solutions that I found online, but none of them seem to work. The error:
SyntaxError: Need to install with `app.use` function
❯ Module.createCompileError ../node_modules/@intlify/message-compiler/dist/message-compiler.mjs:78:19
76| : code;
77| const error = new SyntaxError(String(msg));
78| error.code = code;
| ^
79| if (loc) {
80| error.location = loc;
❯ createI18nError ../node_modules/vue-i18n/dist/vue-i18n.mjs:81:34
❯ Module.useI18n ../node_modules/vue-i18n/dist/vue-i18n.mjs:2184:15
❯ setup components/user/sign-in-form/UserSignInForm.vue:19:19
❯ wrappedSetup ../node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:96:28
❯ clonedComponent.setup ../node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:161:48
❯ callWithErrorHandling ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19
❯ setupStatefulComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7848:25
❯ setupComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7809:36
❯ mountComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5159:7
SyntaxError: Need to install with `app.use` function
❯ Module.createCompileError ../node_modules/@intlify/message-compiler/dist/message-compiler.mjs:78:19
76| : code;
77| const error = new SyntaxError(String(msg));
78| error.code = code;
| ^
79| if (loc) {
80| error.location = loc;
❯ createI18nError ../node_modules/vue-i18n/dist/vue-i18n.mjs:81:34
❯ Module.useI18n ../node_modules/vue-i18n/dist/vue-i18n.mjs:2184:15
❯ setup components/user/sign-in-form/UserSignInForm.vue:19:19
❯ wrappedSetup ../node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:96:28
❯ clonedComponent.setup ../node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:161:48
❯ callWithErrorHandling ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19
❯ setupStatefulComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7848:25
❯ setupComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7809:36
❯ mountComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5159:7
5 replies
NNuxt
Created by ægteemil on 11/10/2024 in #❓・help
Modify file generated from `nuxt add component`
Hey. Can I modify the file that gets generated from various nuxt add commands?
4 replies
NNuxt
Created by ægteemil on 8/4/2024 in #❓・help
Strongly typed i18n
Hey. I'm using the i18n module for nuxt, and I'm wondering if there's a way to achieve type-safety when using translation keys in template? So instead of a magic string, being able to reference something type-safe indicating that they key exists
<p>{{ $t('hello.world') }}</p>
<p>{{ $t(hello.world) }}</p> // this would be nice
<p>{{ $t('hello.world') }}</p>
<p>{{ $t(hello.world) }}</p> // this would be nice
2 replies
NNuxt
Created by ægteemil on 7/21/2024 in #❓・help
WARN [unimport] failed to resolve [type], scip scanning
Hey. I'm using a library to automatically create a service to match my backend API from its open-api spec. I've added the types from this as an auto import:
imports: {
dirs: ['services/gilbert-api'],
},
imports: {
dirs: ['services/gilbert-api'],
},
This directory has four files, index.ts and the files it's showing an error for. index.ts exports the other three files - maybe this is causing the issue? This is working, and I can use the types specified in these files, but it's spitting out an error when i run dev or any type-checking. WARN [unimport] failed to resolve "C:/git/Gilbert/src/Gilbert.App/app/services/gilbert-api/schemas.gen", skip scanning WARN [unimport] failed to resolve "C:/git/Gilbert/src/Gilbert.App/app/services/gilbert-api/services.gen", skip scanning WARN [unimport] failed to resolve "C:/git/Gilbert/src/Gilbert.App/app/services/gilbert-api/types.gen", skip scanning
1 replies
CC#
Created by ægteemil on 7/17/2024 in #help
✅ Describing `object` response in swagger
Hey. I have an endpoint that returns an object that looks something like this.
public record Webhook(
string Id,
PayloadType Type,
object Payload
);
public record Webhook(
string Id,
PayloadType Type,
object Payload
);
where Payload can change depending on the enum value. In typescript or other languages, I'd represent this object as a union type, but since we don't have that in C#, I'd just like to describe the possibilities of this in my swagger documentation
14 replies
CC#
Created by ægteemil on 7/13/2024 in #help
✅ Apply multiple attributes from custom attribute
Hey. I want to encapsulate some duplicated logic from a custom attribute. Right now I'm decorating endpoints with multiple attributes, and I'd like to be apply to just apply my own custom attribute, and have that attribute apply multiple other attributes. So my custom attribute would look like this(?):
public class TestAttribute : Attribute
{
[MyFirstAttribute(name)]
[MySecondAttribute(name)]
public TestAttribute(string name)
{
Name = name;
}

public string Name { get; }
}
public class TestAttribute : Attribute
{
[MyFirstAttribute(name)]
[MySecondAttribute(name)]
public TestAttribute(string name)
{
Name = name;
}

public string Name { get; }
}
12 replies
NNuxt
Created by ægteemil on 7/12/2024 in #❓・help
Route guards for user permissions
Hey. I want to add navigation guards that check if a user has a required permissions before nagivation to a given page, or any sub-pages of it. Right now I have a somewhat crude implementation, and I'm curious if there's a better way of handling it.
if (to.fullPath.startsWith('/customers') && currentUserPermissions?.includes(Permission.CUSTOMER_READ))
return true;

if (to.fullPath.startsWith('/sales') && currentUserPermissions?.includes(Permission.SALES_READ))
return true;

// .. more

return abortNavigation(
createError({
statusCode: 403,
message: 'You do not have permissions to access this page.',
}),
);
if (to.fullPath.startsWith('/customers') && currentUserPermissions?.includes(Permission.CUSTOMER_READ))
return true;

if (to.fullPath.startsWith('/sales') && currentUserPermissions?.includes(Permission.SALES_READ))
return true;

// .. more

return abortNavigation(
createError({
statusCode: 403,
message: 'You do not have permissions to access this page.',
}),
);
5 replies
NNuxt
Created by ægteemil on 6/12/2024 in #❓・help
Centered grid with different-sized children
No description
2 replies
NNuxt
Created by ægteemil on 3/12/2024 in #❓・help
`useAsyncState` equivalent in Nuxt
Hey. Up until now I've been using useAsyncState from VueUse when doing any CRUD work through a service of mine, and I'm curious if this is bad practice and if there's an equivalent function baked into Nuxt? Today I'm doing something like this, which I'm looking to translate similarly to a Nuxt composable of some sort:
const { isLoading, execute: createApiKey } = useAsyncState(async (name: string) => {
await CustomersService.create({ name: name });
}, null, {
immediate: false,
onError: (error) => {
useApiErrorToast(error);
}
});
const { isLoading, execute: createApiKey } = useAsyncState(async (name: string) => {
await CustomersService.create({ name: name });
}, null, {
immediate: false,
onError: (error) => {
useApiErrorToast(error);
}
});
3 replies
CC#
Created by ægteemil on 6/23/2023 in #help
❔ streaming an IAsyncEnumerable<string> from complex type
hey. i have a minimal api that looks like this:
public static async IAsyncEnumerable<string> AskOpenAi(
[FromQuery] string question,
[FromServices] IOpenAIService openAiService)
{
var completionResult = openAiService.ChatCompletion.CreateCompletionAsStream(new ChatCompletionCreateRequest
{
Messages = new List<ChatMessage>
{
new(StaticValues.ChatMessageRoles.System, "You are a helpful assistant."),
new(StaticValues.ChatMessageRoles.User, question),
},
Model = Models.ChatGpt3_5Turbo,
MaxTokens = 150
});

await foreach (var completion in completionResult)
yield return completion.Choices.First().Message.Content;
}
public static async IAsyncEnumerable<string> AskOpenAi(
[FromQuery] string question,
[FromServices] IOpenAIService openAiService)
{
var completionResult = openAiService.ChatCompletion.CreateCompletionAsStream(new ChatCompletionCreateRequest
{
Messages = new List<ChatMessage>
{
new(StaticValues.ChatMessageRoles.System, "You are a helpful assistant."),
new(StaticValues.ChatMessageRoles.User, question),
},
Model = Models.ChatGpt3_5Turbo,
MaxTokens = 150
});

await foreach (var completion in completionResult)
yield return completion.Choices.First().Message.Content;
}
it's registered like this:
app.MapGet("", AskOpenAiEndpoint.AskOpenAi);
app.MapGet("", AskOpenAiEndpoint.AskOpenAi);
but whenever i visit the url, the answer is not being streamed but rather returend as one large string. i tried making a dummy endpoint that works like expected, but im unsure how to modify the above code so it works. this is the test that worked for me:
public static async IAsyncEnumerable<string> Test()
{
var values = new[] { "value1", "value2", "value3", "value4" };
foreach (var item in values)
{
await Task.Delay(1000);
yield return item;
}
}
public static async IAsyncEnumerable<string> Test()
{
var values = new[] { "value1", "value2", "value3", "value4" };
foreach (var item in values)
{
await Task.Delay(1000);
yield return item;
}
}
13 replies
CC#
Created by ægteemil on 4/20/2023 in #help
❔ Swagger shows unwanted schemas when with minimal api
2 replies
CC#
Created by ægteemil on 4/2/2023 in #help
❔ Required select field missing validation error message on iOS
Hey. If I create a required select field, and the select field is outside the current viewport (ie., if you've scrolled further down on the page), the browser doesn't jump to the required select and the validation message is missing. I managed to find a recent stackoverflow question for exactly this, but there's no comments on it. Does anyone here have an idea for how to fix it? https://stackoverflow.com/questions/75854715/html5-form-validation-with-select-field-on-ios-15-16-bug
2 replies
CC#
Created by ægteemil on 11/26/2022 in #help
❔ The foreign key property 'UserRole.RoleId1' was created in shadow state
I've expanded the default IdentityUserRole implementation for .NET identity like this:
public class UserRole : IdentityUserRole<Guid>
{
public Guid TenantId { get; set; }
public virtual Tenant Tenant { get; set; } = null!;

public virtual User User { get; set; } = null!;
public virtual Role Role { get; set; } = null!;
}
public class UserRole : IdentityUserRole<Guid>
{
public Guid TenantId { get; set; }
public virtual Tenant Tenant { get; set; } = null!;

public virtual User User { get; set; } = null!;
public virtual Role Role { get; set; } = null!;
}
And I've included the User and Role as navigation properties, which is now causing EF to write this when creating a migration: The foreign key property 'UserRole.RoleId1' was created in shadow state because a conflicting property with the simple name 'RoleId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type I'm not sure how to configure this properly and avoid the new foreign key property
2 replies
CC#
Created by ægteemil on 11/13/2022 in #help
❔ Customizing assigned roles on sign in using SignInManager
3 replies
CC#
Created by ægteemil on 8/31/2022 in #help
Disable bootstrap multiselect options after selecting
Hi. I have a bootstrap <select multiple/>. When one is selected, I want to disable all other selections temporarily (while waiting for an API response), then enable them again after the response. I can't seem to find a good example of this
6 replies