-
Notifications
You must be signed in to change notification settings - Fork 0
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
adding support for standalone npm package #12
Conversation
based on the "tempOutput" 9cd24ad42cbdfcbe22735b8113efbe770e0e0b2e
// [slug]/+server.ts export declare const Slug = 'slug' e530ae5ccca94b224dbe16fc332acdc1f4d141e0
603c60055ac4106da763f752beb11c47b47ea8c8
Thanks! Since my last commits few months ago I see that svelte-package updated to 2.0.1 rendering my helper functions useless. So I'mma just merge this and clean the project up a bit. Thank you for helping me out! |
@kauderk Would you mind seeing if the standalone for your project works with the latest version? |
|
|
I want to process generics on my endpoints, I've been working on a schema that maps generic types: here https://stackblitz.com/edit/github-bifnc9?file=package.json,src%2Froutes%2Fquery%2Fdemo.ts |
Ah okay, so you something along the lines of this? // api/query/+server.ts
export async function GET<const Q>(event: API<{ query: Q }>) {
return Ok({
body: {...} as Q
})
}
// somewhere.js
api.query.GET({ query: { something: 'abc' as const } })
.Ok(res => {
res.body
// ^? body: Q = { something: 'abc' }
}) |
|
I see! So for the most recent version of sveltekit-zero-api you can use the
In b788348 where I fixed an issue, you can see I created a minimal reproduction inside the package so I could see how changes would reflect immediately. Let me know if I can help🦒 |
@kauderk Do you mind sharing what you've made? I considered the suggestion and it's probably not straight forward. The input and the returned type from the Rest API method are separate like so: So the question becomes how to make them correlated in a meaningful way. I sort of have an idea for an approach, and I could probably look into it. |
I wanted to track down the types so I decided to use import/export types instead of references https://github.com/kauderk/sveltekit-zero-api/tree/generics/src/lib/types |
Yeah understandable. And the refactoring makes sense. I was learning about ambient types and referencing types when I was writing that part — and have since learned that was not the way to do it. I'll see what I can do about the generic. I'm trying to do interface Post {
query: { ... }
}
export function POST<const R extends Post>(event: API<R>) {
...
} Where |
I'm waiting for some help on the TypeScript community on Discord I made a TypeScript Playground if you have any ideas to try out |
The best attempt we could do as stated in the Discord conversation is to handle the typed API like export type GeneratedAPI = {
users: {
GET: Z<typeof userEndpoint.GET<{...}>>
}
} Honestly that's the closest solution I can think of. And yet, I don't know how we would pass the RequestInit inside here. There's no easy solution atm anyways🦒 |
This seems like it will it requiere some heavy "type drilling". |
Yeah exactly. I think we have to "solidify" the types from where they are imported (inside So...
The only concerning thing I have is the Regex as I don't know how that will impact the performance. I wouldn't personally care too much really, so I think it would be a valid strategy. |
Done #15 (comment) |
I've created a standalone npm package for the youtube-browser-api and made the necessary changes to the original repository to support it. This allows developers to use the API without having to set up a SvelteKit project.
Here are the commits included in this pull request:
Please let me know if you have any questions or concerns.