This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
nested.ts
59 lines (54 loc) · 1.81 KB
/
nested.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @license BSD-3-Clause
*
* Copyright (c) 2019 Project Jupyter Contributors.
* Distributed under the terms of the 3-Clause BSD License.
*/
/**
* * Switch data to not have to be observable.
* * In registry just have an observable of adding and removing lists of
*
* A nested dataset has an observable set of URLs of other datasets that are within it.
*
* The user story here is:
*
* * User expands folder in data registry
* * We subscribe to the nested datasets within that URL.
* * For each of the URLs, we registry that as a resolve dataset.
*
* ---
*
* * In the registry, assume the converters don't change and we can only register URLs
* * We also assume we just have a set of URLs and a set of converters.
* * In the registry, we have a `register` function that takes in a URL
*
* * For the explorer, we have a top level `explorer:` URL that has a list of URLS to display.
*/
import { URL_ } from './datasets';
import { DataTypeNoArgs } from './datatypes';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { createConverter } from './createConverter';
/**
* a list of relative URLs to resolve against the current URL.
*
* Uses an array instead of a set and ends in +json for notebook mimetype compatability
*/
export const relativeNestedDataType = new DataTypeNoArgs<
Observable<Array<string>>
>('application/x.jupyter.relative-dataset-urls+json');
/**
* A nested data type has datasets inside of it.
*/
export const nestedDataType = new DataTypeNoArgs<Observable<Set<URL_>>>(
'application/x.jupyter.dataset-urls'
);
export const relativeNestedURLConverter = createConverter(
{ from: relativeNestedDataType, to: nestedDataType },
({ data, url }) =>
data.pipe(
map(
(relURLs) => new Set(relURLs.map((relURL) => new URL(relURL, url).href))
)
)
);