@@ -2,7 +2,48 @@ import { type RepoFullName, type RepoType, listFiles } from '@huggingface/hub'
22import type { DirSource , FileMetadata , FileSource , SourcePart } from './types.js'
33import { getFileName } from './utils.js'
44
5- export const baseUrl = 'https://huggingface.co'
5+ interface BaseUrl {
6+ source : string
7+ origin : string
8+ type : RepoType
9+ repo : string
10+ branch : string
11+ path : string
12+ }
13+
14+ interface DirectoryUrl extends BaseUrl {
15+ kind : 'directory'
16+ action : 'tree'
17+ }
18+
19+ interface FileUrl extends BaseUrl {
20+ kind : 'file'
21+ action : 'resolve' | 'blob'
22+ resolveUrl : string
23+ }
24+
25+ type HFUrl = DirectoryUrl | FileUrl ;
26+
27+ interface RefResponse {
28+ name : string ;
29+ ref : string ;
30+ targetCommit : string ;
31+ }
32+
33+ const refTypes = [
34+ 'branches' ,
35+ 'tags' ,
36+ 'converts' ,
37+ 'pullRequests' ,
38+ ] as const
39+ type RefType = ( typeof refTypes ) [ number ] ;
40+ type RefsResponse = Partial < Record < RefType , RefResponse [ ] > > ;
41+
42+ interface RefMetadata extends RefResponse {
43+ refType : RefType ; // TODO(SL): use it to style the refs differently?
44+ }
45+
46+ const baseUrl = 'https://huggingface.co'
647
748function getFullName ( url : HFUrl ) : RepoFullName {
849 return url . type === 'dataset' ? `datasets/${ url . repo } ` : url . type === 'space' ? `spaces/${ url . repo } ` : url . repo
@@ -105,28 +146,6 @@ export function getHuggingFaceSource(sourceId: string, options?: {requestInit?:
105146 }
106147}
107148
108- interface BaseUrl {
109- source : string
110- origin : string
111- type : RepoType
112- repo : string
113- branch : string
114- path : string
115- }
116-
117- export interface DirectoryUrl extends BaseUrl {
118- kind : 'directory'
119- action : 'tree'
120- }
121-
122- export interface FileUrl extends BaseUrl {
123- kind : 'file'
124- action : 'resolve' | 'blob'
125- resolveUrl : string
126- }
127-
128- type HFUrl = DirectoryUrl | FileUrl ;
129-
130149export function parseHuggingFaceUrl ( url : string ) : HFUrl {
131150 const urlObject = new URL ( url )
132151 // ^ throws 'TypeError: URL constructor: {url} is not a valid URL.' if url is not a valid URL
@@ -225,25 +244,6 @@ export function parseHuggingFaceUrl(url: string): HFUrl {
225244 throw new Error ( 'Unsupported Hugging Face URL' )
226245}
227246
228- interface RefResponse {
229- name : string ;
230- ref : string ;
231- targetCommit : string ;
232- }
233-
234- export const refTypes = [
235- 'branches' ,
236- 'tags' ,
237- 'converts' ,
238- 'pullRequests' ,
239- ] as const
240- type RefType = ( typeof refTypes ) [ number ] ;
241- type RefsResponse = Partial < Record < RefType , RefResponse [ ] > > ;
242-
243- export interface RefMetadata extends RefResponse {
244- refType : RefType ; // TODO(SL): use it to style the refs differently?
245- }
246-
247247/**
248248 * List refs in a HF dataset repo
249249 *
0 commit comments