Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stupid-pugs-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-kit-routes": patch
---

add routes as Set (with all routes options) & Routes type.
34 changes: 13 additions & 21 deletions packages/vite-plugin-kit-routes/src/lib/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ const PAGES = {
params?: { lang?: 'fr' | 'en' | 'hu' | 'at' | string; limit?: number },
sp?: Record<string, string | number>,
) => {
return `${params?.lang ? `/${params?.lang}` : ''}/site${appendSp({
...sp,
limit: params?.limit,
})}`
return `${params?.lang ? `/${params?.lang}` : ''}/site${appendSp({ ...sp, limit: params?.limit })}`
},
'/site/[id]': (params?: {
lang?: 'fr' | 'hu' | undefined
Expand All @@ -60,20 +57,15 @@ const PAGES = {
params = params ?? {}
params.lang = params.lang ?? 'fr'
params.id = params.id ?? 'Vienna'
return `${params?.lang ? `/${params?.lang}` : ''}/site/${params.id}${appendSp({
limit: params.limit,
demo: params.demo,
})}`
return `${params?.lang ? `/${params?.lang}` : ''}/site/${params.id}${appendSp({ limit: params.limit, demo: params.demo })}`
},
'/site_contract/[siteId]-[contractId]': (params: {
siteId: string | number
contractId: string | number
lang?: 'fr' | 'en' | 'hu' | 'at' | string
limit?: number
}) => {
return `${params?.lang ? `/${params?.lang}` : ''}/site_contract/${params.siteId}-${
params.contractId
}${appendSp({ limit: params.limit })}`
return `${params?.lang ? `/${params?.lang}` : ''}/site_contract/${params.siteId}-${params.contractId}${appendSp({ limit: params.limit })}`
},
'/a/[...rest]/z': (params: { rest: (string | number)[] }) => {
return `/a/${params.rest?.join('/')}/z`
Expand Down Expand Up @@ -123,18 +115,13 @@ const ACTIONS = {
lang?: 'fr' | 'en' | 'hu' | 'at' | string
limit?: number
}) => {
return `${params?.lang ? `/${params?.lang}` : ''}/contract/${params.id}${appendSp({
limit: params.limit,
})}`
return `${params?.lang ? `/${params?.lang}` : ''}/contract/${params.id}${appendSp({ limit: params.limit })}`
},
'create /site': (params?: {
lang?: 'fr' | 'en' | 'hu' | 'at' | string
redirectTo?: 'list' | 'new' | 'detail'
}) => {
return `${params?.lang ? `/${params?.lang}` : ''}/site?/create${appendSp(
{ redirectTo: params?.redirectTo },
'&',
)}`
return `${params?.lang ? `/${params?.lang}` : ''}/site?/create${appendSp({ redirectTo: params?.redirectTo }, '&')}`
},
'update /site/[id]': (params: {
id: string | number
Expand All @@ -158,9 +145,7 @@ const ACTIONS = {
extra?: 'A' | 'B'
}) => {
params.extra = params.extra ?? 'A'
return `${params?.lang ? `/${params?.lang}` : ''}/site_contract/${params.siteId}-${
params.contractId
}?/send${appendSp({ extra: params.extra }, '&')}`
return `${params?.lang ? `/${params?.lang}` : ''}/site_contract/${params.siteId}-${params.contractId}?/send${appendSp({ extra: params.extra }, '&')}`
},
}

Expand Down Expand Up @@ -247,6 +232,13 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}`
? `/${Route}`
: keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
5 changes: 5 additions & 0 deletions packages/vite-plugin-kit-routes/src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends \`\${string}/\${infer Route}\` ? \`/\${Route}\` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\\/.*|[^ ]?\\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* \`\`\`ts
Expand Down
5 changes: 5 additions & 0 deletions packages/vite-plugin-kit-routes/src/test/ROUTES_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never
const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS }
type AllTypes = typeof AllObjs

export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes
export const routes = [
...new Set(Object.keys(AllObjs).map((route) => /^\/.*|[^ ]?\/.*$/.exec(route)?.[0] ?? route)),
] as Routes[]

/**
* To be used like this:
* ```ts
Expand Down