@@ -7,8 +7,8 @@ import { getOrderedSchemaKeys } from '../schema'
7
7
import { parseSourceBase } from './utils'
8
8
import { withoutRoot } from './files'
9
9
10
- export const getCollectionByFilePath = ( path : string , collections : Record < string , CollectionInfo > ) : { collection : CollectionInfo , matchedSource : ResolvedCollectionSource } => {
11
- let matchedSource : ResolvedCollectionSource
10
+ export const getCollectionByFilePath = ( path : string , collections : Record < string , CollectionInfo > ) : { collection : CollectionInfo | undefined , matchedSource : ResolvedCollectionSource | undefined } => {
11
+ let matchedSource : ResolvedCollectionSource | undefined
12
12
const collection = Object . values ( collections ) . find ( ( collection ) => {
13
13
if ( ! collection . source || collection . source . length === 0 ) {
14
14
return
@@ -28,21 +28,21 @@ export const getCollectionByFilePath = (path: string, collections: Record<string
28
28
}
29
29
}
30
30
31
- export const getCollectionByRoutePath = ( routePath : string , collections : Record < string , CollectionInfo > ) : { collection : CollectionInfo , matchedSource : ResolvedCollectionSource } => {
32
- let matchedSource : ResolvedCollectionSource
31
+ export const getCollectionByRoutePath = ( routePath : string , collections : Record < string , CollectionInfo > ) : { collection : CollectionInfo | undefined , matchedSource : ResolvedCollectionSource | undefined } => {
32
+ let matchedSource : ResolvedCollectionSource | undefined
33
33
const collection = Object . values ( collections ) . find ( ( collection ) => {
34
34
if ( ! collection . source || collection . source . length === 0 ) {
35
35
return
36
36
}
37
37
38
38
matchedSource = collection . source . find ( ( source ) => {
39
- if ( ! routePath . startsWith ( source . prefix ) ) {
39
+ if ( ! source . prefix || ! routePath . startsWith ( source . prefix ) ) {
40
40
return
41
41
}
42
42
43
43
if ( routePath === '/' || routePath === source . prefix ) {
44
44
const indexFiles = [ 'index.yml' , 'index.yaml' , 'index.md' , 'index.json' ]
45
- const files = routePath === '/' ? indexFiles : indexFiles . map ( file => withoutLeadingSlash ( joinURL ( source . prefix , file ) ) )
45
+ const files = routePath === '/' ? indexFiles : indexFiles . map ( file => withoutLeadingSlash ( joinURL ( source . prefix ! , file ) ) )
46
46
return files . some ( ( p ) => {
47
47
return collection . source . find ( source => minimatch ( p , source . include ) && ! source . exclude ?. some ( exclude => minimatch ( p , exclude ) ) )
48
48
} )
@@ -98,7 +98,7 @@ export function generateRecordSelectByColumn(collection: CollectionInfo, column:
98
98
function computeValuesBasedOnCollectionSchema ( collection : CollectionInfo , data : Record < string , unknown > ) {
99
99
const fields : string [ ] = [ ]
100
100
const values : Array < string | number | boolean > = [ ]
101
- const properties = ( collection . schema . definitions [ collection . name ] as JsonSchema7ObjectType ) . properties
101
+ const properties = ( collection . schema . definitions ! [ collection . name ] as JsonSchema7ObjectType ) . properties
102
102
const sortedKeys = getOrderedSchemaKeys ( properties )
103
103
104
104
sortedKeys . forEach ( ( key ) => {
0 commit comments