| 210 | } |
| 211 | |
| 212 | export function _getSourceIdAssigner(sourceIdKey: StringOrDocFunc | null): (doc: DocumentInterface) => string | null { |
| 213 | if (sourceIdKey === null) { |
| 214 | return (_doc: DocumentInterface) => null |
| 215 | } else if (typeof sourceIdKey === 'string') { |
| 216 | return (doc: DocumentInterface) => doc.metadata[sourceIdKey] |
| 217 | } else if (typeof sourceIdKey === 'function') { |
| 218 | return sourceIdKey |
| 219 | } else { |
| 220 | throw new Error(`sourceIdKey should be null, a string or a function, got ${typeof sourceIdKey}`) |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | export const _isBaseDocumentLoader = (arg: any): arg is BaseDocumentLoader => { |
| 225 | if ('load' in arg && typeof arg.load === 'function' && 'loadAndSplit' in arg && typeof arg.loadAndSplit === 'function') { |