Skip to content

Commit

Permalink
Lets leave ModelNames as default
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Sep 5, 2024
1 parent 1a0f8b9 commit 19f65f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
23 changes: 10 additions & 13 deletions packages/storage/src/__typetests__/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { expect, test } from 'tstyche'
import { createUploadsConfig, setupStorage } from 'src/index.js'

import { MemoryStorage } from '../adapters/MemoryStorage/MemoryStorage.js'
import type { ModelNames } from '../prismaExtension.js'
import { type UploadsConfig } from '../prismaExtension.js'

// Use the createUplodsConfig helper here....
Expand Down Expand Up @@ -54,28 +53,26 @@ test('inline config for save files is OK!', () => {
})

test('UploadsConfig accepts all available models with their fields', async () => {
type ConfiguredUploadsConfig = UploadsConfig<ModelNames>
expect<UploadsConfig>().type.toHaveProperty('dummy')
expect<UploadsConfig>().type.toHaveProperty('dumbo')
expect<UploadsConfig>().type.toHaveProperty('book')
expect<UploadsConfig>().type.toHaveProperty('bookCover')
expect<UploadsConfig>().type.toHaveProperty('noUploadFields')

expect<ConfiguredUploadsConfig>().type.toHaveProperty('dummy')
expect<ConfiguredUploadsConfig>().type.toHaveProperty('dumbo')
expect<ConfiguredUploadsConfig>().type.toHaveProperty('book')
expect<ConfiguredUploadsConfig>().type.toHaveProperty('bookCover')
expect<ConfiguredUploadsConfig>().type.toHaveProperty('noUploadFields')

expect<ConfiguredUploadsConfig['dumbo']>().type.toBeAssignableWith<{
expect<UploadsConfig['dumbo']>().type.toBeAssignableWith<{
fields: ['firstUpload'] // one of the fields, but not all of them
}>()

expect<ConfiguredUploadsConfig['dumbo']>().type.toBeAssignableWith<{
expect<UploadsConfig['dumbo']>().type.toBeAssignableWith<{
fields: ['firstUpload', 'secondUpload'] // one of the fields, but not all of them
}>()

expect<ConfiguredUploadsConfig['bookCover']>().type.toBeAssignableWith<{
fields: ['photo']
expect<UploadsConfig['bookCover']>().type.toBeAssignableWith<{
fields: 'photo'
}>()

// If you give it something else, it won't accept it
expect<ConfiguredUploadsConfig['bookCover']>().type.not.toBeAssignableWith<{
expect<UploadsConfig['bookCover']>().type.not.toBeAssignableWith<{
fields: ['bazinga']
}>()
})
2 changes: 1 addition & 1 deletion packages/storage/src/prismaExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type UploadConfigForModel<TPrismaModelName extends ModelNames> = {
| PrismaModelFields<TPrismaModelName>[]
}

export type UploadsConfig<MNames extends ModelNames> = {
export type UploadsConfig<MNames extends ModelNames = ModelNames> = {
[K in MNames]?: UploadConfigForModel<K>
}

Expand Down

0 comments on commit 19f65f3

Please sign in to comment.