11import { minimatch } from 'minimatch'
22import type { CollectionInfo } from '@nuxt/content'
33// import { joinURL, withoutLeadingSlash } from 'ufo'
4+ import type { JsonSchema7ObjectType } from 'zod-to-json-schema'
45import { getOrderedSchemaKeys } from '../schema'
56// import { parseSourceBase } from './utils'
67import { withoutRoot } from './files'
78
89export const getCollectionByPath = ( path : string , collections : Record < string , CollectionInfo > ) : CollectionInfo => {
910 return Object . values ( collections ) . find ( ( collection ) => {
10- if ( ! collection . source ) {
11+ if ( ! collection . source || collection . source . length === 0 ) {
1112 return
1213 }
1314
@@ -26,7 +27,7 @@ export const getCollectionByPath = (path: string, collections: Record<string, Co
2627
2728 const paths = pathWithoutRoot === '/' ? [ 'index.yml' , 'index.yaml' , 'index.md' , 'index.json' ] : [ pathWithoutRoot ]
2829 return paths . some ( ( p ) => {
29- return minimatch ( p , collection . source . include )
30+ return collection . source . some ( source => minimatch ( p , source . include ) )
3031 } )
3132 } )
3233}
@@ -59,13 +60,13 @@ export function generateRecordSelectByColumn(collection: CollectionInfo, column:
5960function computeValuesBasedOnCollectionSchema ( collection : CollectionInfo , data : Record < string , unknown > ) {
6061 const fields : string [ ] = [ ]
6162 const values : Array < string | number | boolean > = [ ]
62- const properties = collection . schema . definitions [ collection . name ] . properties
63+ const properties = ( collection . schema . definitions [ collection . name ] as JsonSchema7ObjectType ) . properties
6364 const sortedKeys = getOrderedSchemaKeys ( properties )
6465
6566 sortedKeys . forEach ( ( key ) => {
6667 const value = ( properties ) [ key ]
6768 // const underlyingType = getUnderlyingType(value as ZodType<unknown, ZodOptionalDef>)
68- const underlyingType = value . type
69+ const underlyingType = ( value as JsonSchema7ObjectType ) . type
6970
7071 const defaultValue = value . default ? value . default : 'NULL'
7172 const valueToInsert = typeof data [ key ] !== 'undefined' ? data [ key ] : defaultValue
0 commit comments