create-kitql
Advanced tools
Comparing version 0.0.4-next.0 to 0.0.4-next.1
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.0.4-next.0", | ||
"version": "0.0.4-next.1", | ||
"license": "MIT", | ||
@@ -12,0 +12,0 @@ "type": "module", |
@@ -33,3 +33,3 @@ { | ||
"vite": "^4.5.0", | ||
"vite-plugin-kit-routes": "0.2.0-next.1", | ||
"vite-plugin-kit-routes": "0.2.0-next.3", | ||
"vitest": "^0.34.0" | ||
@@ -36,0 +36,0 @@ }, |
@@ -83,3 +83,3 @@ /** | ||
export function route<T extends keyof AllTypes>(key: T, ...params: any[]): string { | ||
if (AllObjs[key] instanceof Function) { | ||
if ((AllObjs[key] as any) instanceof Function) { | ||
const element = (AllObjs as any)[key] as (...args: any[]) => string; | ||
@@ -86,0 +86,0 @@ return element(...params); |
@@ -34,3 +34,3 @@ { | ||
"vite": "^4.5.0", | ||
"vite-plugin-kit-routes": "^0.1.1", | ||
"vite-plugin-kit-routes": "0.2.0-next.3", | ||
"vitest": "^0.34.0" | ||
@@ -37,0 +37,0 @@ }, |
@@ -7,11 +7,23 @@ /** | ||
export const PAGES = { | ||
/** | ||
* PAGES | ||
*/ | ||
const PAGES = { | ||
'/': `/` | ||
}; | ||
export const SERVERS = {}; | ||
/** | ||
* SERVERS | ||
*/ | ||
const SERVERS = {}; | ||
export const ACTIONS = {}; | ||
/** | ||
* ACTIONS | ||
*/ | ||
const ACTIONS = {}; | ||
export const LINKS = { | ||
/** | ||
* LINKS | ||
*/ | ||
const LINKS = { | ||
twitter_jycouet: `https:/twitter.com/jycouet`, | ||
@@ -22,3 +34,6 @@ github_kitql: `https:/github.com/jycouet/kitql`, | ||
const appendSp = (sp?: Record<string, string | number | undefined>) => { | ||
/** | ||
* Append search params to a string | ||
*/ | ||
const appendSp = (sp?: Record<string, string | number | undefined>, prefix: '?' | '&' = '?') => { | ||
if (sp === undefined) return ''; | ||
@@ -31,3 +46,3 @@ const mapping = Object.entries(sp) | ||
if (formated) { | ||
return `?${formated}`; | ||
return `${prefix}${formated}`; | ||
} | ||
@@ -37,3 +52,33 @@ return ''; | ||
// route function helpers | ||
type NonFunctionKeys<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T]; | ||
type FunctionKeys<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; | ||
type FunctionParams<T> = T extends (...args: infer P) => any ? P : never; | ||
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }; | ||
type AllTypes = typeof AllObjs; | ||
/** | ||
* To be used like this: | ||
* ```ts | ||
* import { route } from './ROUTES' | ||
* | ||
* route('site_id', { id: 1 }) | ||
* ``` | ||
*/ | ||
export function route<T extends FunctionKeys<AllTypes>>( | ||
key: T, | ||
...params: FunctionParams<AllTypes[T]> | ||
): string; | ||
export function route<T extends NonFunctionKeys<AllTypes>>(key: T): string; | ||
export function route<T extends keyof AllTypes>(key: T, ...params: any[]): string { | ||
if ((AllObjs[key] as any) instanceof Function) { | ||
const element = (AllObjs as any)[key] as (...args: any[]) => string; | ||
return element(...params); | ||
} else { | ||
return AllObjs[key] as string; | ||
} | ||
} | ||
/** | ||
* Add this type as a generic of the vite plugin `kitRoutes<KIT_ROUTES>`. | ||
@@ -48,3 +93,3 @@ * | ||
* PAGES: { | ||
* // here, "paths" it will be typed! | ||
* // here, key of object will be typed! | ||
* } | ||
@@ -56,6 +101,6 @@ * }) | ||
PAGES: { '/': never }; | ||
SERVERS: {}; | ||
ACTIONS: {}; | ||
SERVERS: Record<string, never>; | ||
ACTIONS: Record<string, never>; | ||
LINKS: { twitter_jycouet: never; github_kitql: never; github_remult: never }; | ||
Params: {}; | ||
Params: Record<string, never>; | ||
}; |
@@ -9,3 +9,2 @@ import { sveltekit } from '@sveltejs/kit/vite'; | ||
kitRoutes({ | ||
logs: [], // removes logs | ||
post_update_run: 'npm exec prettier ./src/lib/ROUTES.ts -- -w', | ||
@@ -12,0 +11,0 @@ LINKS: { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
68555
670
0