Skip to content

Commit

Permalink
Fix/types empty (#500)
Browse files Browse the repository at this point in the history
* 🚧 UPDATE: add sp

* 🐛 FIX: type when there is no element in the Record (#499)
  • Loading branch information
jycouet authored Nov 25, 2023
1 parent 60f899f commit e43bb98
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 73 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-scissors-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-kit-routes': patch
---

fix: type when there is no element in the Record
46 changes: 0 additions & 46 deletions .eslintrc.cjs

This file was deleted.

3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ $houdini
$kitql
stats.html

db/
db/
ROUTES_*
11 changes: 0 additions & 11 deletions packages/eslint-config-kitql/.eslintignore

This file was deleted.

8 changes: 7 additions & 1 deletion packages/eslint-config-kitql/index.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:svelte/recommended',
],
plugins: ['unused-imports', 'svelte', '@typescript-eslint'],
rules: {
'no-console': ['error', { allow: ['info', 'warn', 'error', 'time', 'timeEnd'] }],
Expand All @@ -10,6 +15,7 @@ module.exports = {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/ban-types': 'error',
},
overrides: [
{
Expand Down
10 changes: 8 additions & 2 deletions packages/vite-plugin-kit-routes/src/lib/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ export const PAGES = {
}) => {
return `${params?.lang ? `/${params?.lang}` : ''}/match/${params.id}`
},
lang_site: (params: { lang?: 'fr' | 'en' | 'hu' | 'at' | string; limit?: number } = {}) => {
return `${params?.lang ? `/${params?.lang}` : ''}/site${appendSp({ limit: params.limit })}`
lang_site: (
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,
})}`
},
lang_site_id: (
params: { lang?: 'fr' | 'hu' | undefined; id?: string; limit?: number; demo?: string } = {},
Expand Down
19 changes: 13 additions & 6 deletions packages/vite-plugin-kit-routes/src/lib/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,13 @@ const shouldLog = (kind: LogKind, options?: Options) => {
return options.logs.includes(kind)
}

const arrayToRecord = (arr?: string[]) => {
if (arr && arr.length > 0) {
return `: { ${arr.join(', ')} }`
}
return `: Record<string, never>`
}

export const run = (options?: Options) => {
let files = getFilesUnder(routes_path())

Expand Down Expand Up @@ -703,8 +710,8 @@ const appendSp = (sp?: Record<string, string | number | undefined>, prefix: '?'
export type KIT_ROUTES = {
${objTypes
.map(c => {
return ` ${c.type}: { ${c.files
.map(d => {
return ` ${c.type}${arrayToRecord(
c.files.map(d => {
return `'${d.keyToUse}': ${
d.paramsFromPath.filter(e => e.fromPath === true).length === 0
? 'never'
Expand All @@ -715,15 +722,15 @@ ${objTypes
})
.join(' | ')
}`
})
.join(', ')} }`
}),
)}`
})
.join('\n')}
Params: { ${[
Params${arrayToRecord([
...new Set(
objTypes.flatMap(c => c.files.flatMap(d => d.paramsFromPath.map(e => `${e.name}: never`))),
),
].join(', ')} }
])}
}
`,
])
Expand Down
5 changes: 1 addition & 4 deletions packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ describe('run()', () => {
extra_search_params: 'with',
},
lang_site: {
// extra_search_params: 'with',
explicit_search_params: { limit: { type: 'number' } },
params: {
// yop: { type: 'number' },
Expand Down Expand Up @@ -541,7 +540,6 @@ describe('run()', () => {
extra_search_params: 'with',
},
lang_site: {
// extra_search_params: 'with',
explicit_search_params: { limit: { type: 'number' } },
params: {
// yop: { type: 'number' },
Expand Down Expand Up @@ -705,7 +703,7 @@ describe('run()', () => {
})
})

it('with_ase', () => {
it('with path base', () => {
const generated_file_path = 'src/test/ROUTES_test5.ts'
run({
generated_file_path,
Expand All @@ -723,7 +721,6 @@ describe('run()', () => {
extra_search_params: 'with',
},
lang_site: {
// extra_search_params: 'with',
explicit_search_params: { limit: { type: 'number' } },
params: {
// yop: { type: 'number' },
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-kit-routes/src/test/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ROUTES*
ROUTES_*
2 changes: 1 addition & 1 deletion packages/vite-plugin-kit-routes/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default defineConfig({
},
},
lang_site: {
// extra_search_params: 'with',
extra_search_params: 'with',
explicit_search_params: { limit: { type: 'number' } },
params: {
// yop: { type: 'number' },
Expand Down

1 comment on commit e43bb98

@vercel
Copy link

@vercel vercel bot commented on e43bb98 Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kitql – ./

kitql-git-main-jycouet.vercel.app
kitql-jycouet.vercel.app
www.kitql.dev
kitql.dev
kitql.vercel.app

Please sign in to comment.