@data-fair/lib-common-types 1.8.4 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/catalog/.type/index.d.ts +110 -0
- package/catalog/.type/index.js +7 -0
- package/catalog/index.d.ts +66 -0
- package/catalog/index.js +1 -0
- package/catalog/schema.d.ts +151 -0
- package/catalog/schema.js +160 -0
- package/package.json +1 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
export const schemaExports: string[]
|
|
3
|
+
|
|
4
|
+
// see https://github.com/bcherny/json-schema-to-typescript/issues/439 if some types are not exported
|
|
5
|
+
/**
|
|
6
|
+
* The list of capabilities that a catalog can have.
|
|
7
|
+
* - listDatasets: The catalog can list datasets and get one dataset
|
|
8
|
+
* - search: The catalog can use a search param in the listDatasets method
|
|
9
|
+
* - pagination: The catalog can paginate the results of the listDatasets method
|
|
10
|
+
* - publishDataset: The catalog can publish and delete datasets
|
|
11
|
+
*
|
|
12
|
+
* This interface was referenced by `HttpsGithubComDataFairLibCatalog`'s JSON-Schema
|
|
13
|
+
* via the `definition` "capability".
|
|
14
|
+
*/
|
|
15
|
+
export type Capability = "listDatasets" | "publishDataset" | "search" | "pagination" | "additionalFilters";
|
|
16
|
+
|
|
17
|
+
export type HttpsGithubComDataFairLibCatalog = {}
|
|
18
|
+
/**
|
|
19
|
+
* The metadata of the catalog plugin
|
|
20
|
+
*
|
|
21
|
+
* This interface was referenced by `HttpsGithubComDataFairLibCatalog`'s JSON-Schema
|
|
22
|
+
* via the `definition` "metadata".
|
|
23
|
+
*/
|
|
24
|
+
export type Metadata = {
|
|
25
|
+
/**
|
|
26
|
+
* The title of the plugin to be displayed in the UI
|
|
27
|
+
*/
|
|
28
|
+
title: string;
|
|
29
|
+
/**
|
|
30
|
+
* The description of the plugin to be displayed in the UI
|
|
31
|
+
*/
|
|
32
|
+
description: string;
|
|
33
|
+
/**
|
|
34
|
+
* The SVG Path icon of the plugin
|
|
35
|
+
*/
|
|
36
|
+
icon: string;
|
|
37
|
+
/**
|
|
38
|
+
* The list of capabilities that a catalog can have.
|
|
39
|
+
*/
|
|
40
|
+
capabilities: Capability[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The normalized dataset format
|
|
44
|
+
*
|
|
45
|
+
* This interface was referenced by `HttpsGithubComDataFairLibCatalog`'s JSON-Schema
|
|
46
|
+
* via the `definition` "catalogDataset".
|
|
47
|
+
*/
|
|
48
|
+
export type CatalogDataset = {
|
|
49
|
+
id: string;
|
|
50
|
+
title: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
keywords?: string[];
|
|
53
|
+
origin?: string;
|
|
54
|
+
image?: string;
|
|
55
|
+
license?: string;
|
|
56
|
+
frequency?: string;
|
|
57
|
+
private?: boolean;
|
|
58
|
+
resources?: CatalogResourceDataset;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The normalized resource format
|
|
62
|
+
*
|
|
63
|
+
* This interface was referenced by `HttpsGithubComDataFairLibCatalog`'s JSON-Schema
|
|
64
|
+
* via the `definition` "catalogResourceDataset".
|
|
65
|
+
*/
|
|
66
|
+
export type CatalogResourceDataset = {
|
|
67
|
+
id: string;
|
|
68
|
+
title: string;
|
|
69
|
+
format: string;
|
|
70
|
+
url: string;
|
|
71
|
+
fileName?: string;
|
|
72
|
+
mimeType?: string;
|
|
73
|
+
size?: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* This interface was referenced by `HttpsGithubComDataFairLibCatalog`'s JSON-Schema
|
|
77
|
+
* via the `definition` "publication".
|
|
78
|
+
*/
|
|
79
|
+
export type Publication = {
|
|
80
|
+
/**
|
|
81
|
+
* Id of this publication, for a better search in database
|
|
82
|
+
*/
|
|
83
|
+
publicationId?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Id of the catalog where the resource is published
|
|
86
|
+
*/
|
|
87
|
+
catalogId: string;
|
|
88
|
+
/**
|
|
89
|
+
* Id of the dataset in the remote catalog
|
|
90
|
+
*/
|
|
91
|
+
remoteDatasetId?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Id of the resource in the dataset in the remote catalog, used if a DataFair dataset is published as a resource in a remote catalog
|
|
94
|
+
*/
|
|
95
|
+
remoteResourceId?: string;
|
|
96
|
+
/**
|
|
97
|
+
* True if the publication is a resource, false or undefined if it is a dataset
|
|
98
|
+
*/
|
|
99
|
+
isResource?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* A simple flag to clearly identify the publications that were successful. If "error" then the error key should be defined.
|
|
102
|
+
*/
|
|
103
|
+
status: "waiting" | "published" | "error" | "deleted";
|
|
104
|
+
/**
|
|
105
|
+
* Date of the last update for this publication
|
|
106
|
+
*/
|
|
107
|
+
publishedAt?: string;
|
|
108
|
+
error?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Capability, Metadata, CatalogDataset, Publication } from './.type/index.js';
|
|
2
|
+
export type { CatalogDataset } from './.type/index.js';
|
|
3
|
+
export type { CatalogResourceDataset } from './.type/index.js';
|
|
4
|
+
export type { Publication } from './.type/index.js';
|
|
5
|
+
/** Utility type to check if a type T includes a type U */
|
|
6
|
+
type Includes<T extends any[], U> = U extends T[number] ? true : false;
|
|
7
|
+
/**
|
|
8
|
+
* Generic catalog plugin interface.
|
|
9
|
+
* @template TCatalogConfig - The type of the catalog configuration.
|
|
10
|
+
* @template TCapabilities - The capabilities of the catalog.
|
|
11
|
+
*/
|
|
12
|
+
export type CatalogPlugin<TCatalogConfig = any, TCapabilities extends Capability[] = any> = BaseCatalogPlugin<TCatalogConfig, TCapabilities> & (Includes<TCapabilities, 'listDatasets'> extends true ? WithListDatasets<TCatalogConfig, TCapabilities> : {}) & (Includes<TCapabilities, 'publishDataset'> extends true ? WithPublishDataset<TCatalogConfig> : {});
|
|
13
|
+
type BaseCatalogPlugin<TCatalogConfig, TCapabilities extends Capability[]> = {
|
|
14
|
+
metadata: CatalogMetadata<TCapabilities>;
|
|
15
|
+
configSchema: TCatalogConfig;
|
|
16
|
+
/** Function to validates the catalog configuration. */
|
|
17
|
+
assertConfigValid(catalogConfig: any): asserts catalogConfig is TCatalogConfig;
|
|
18
|
+
};
|
|
19
|
+
type WithListDatasets<TCatalogConfig, TCapabilities extends Capability[]> = {
|
|
20
|
+
/** List available datasets in the catalog. */
|
|
21
|
+
listDatasets: (catalogConfig: TCatalogConfig, params: ListDatasetsParams<TCapabilities>) => Promise<{
|
|
22
|
+
count: number;
|
|
23
|
+
results: CatalogDataset[];
|
|
24
|
+
}>;
|
|
25
|
+
/** Get a specific dataset. */
|
|
26
|
+
getDataset: (catalogConfig: TCatalogConfig, datasetId: string) => Promise<CatalogDataset | undefined>;
|
|
27
|
+
} & (Includes<TCapabilities, 'additionalFilters'> extends true ? {
|
|
28
|
+
filtersSchema: Record<string, any>;
|
|
29
|
+
} : {});
|
|
30
|
+
type WithPublishDataset<TCatalogConfig> = {
|
|
31
|
+
/**
|
|
32
|
+
* Publish/Update a dataset or add/update a resource to a dataset
|
|
33
|
+
* @param catalogConfig The configuration of the catalog
|
|
34
|
+
* @param dataset The datafair dataset to publish
|
|
35
|
+
* @param publication The publication in the datafair dataset to process
|
|
36
|
+
* @returns A promise that resolves to the updated publication object with the publicationId, the remoteDatasetId and the status after the dataset is published
|
|
37
|
+
*/
|
|
38
|
+
publishDataset: (catalogConfig: TCatalogConfig, dataset: any, publication: Publication) => Promise<Publication>;
|
|
39
|
+
/**
|
|
40
|
+
* Delete a dataset or remove a resource from a dataset
|
|
41
|
+
* @param catalogConfig The configuration of the catalog
|
|
42
|
+
* @param datasetId The id of the remoteDataset to delete, or the dataset where the resource to delete is
|
|
43
|
+
* @param resourceId The id of the resource to delete
|
|
44
|
+
*/
|
|
45
|
+
deleteDataset: (catalogConfig: TCatalogConfig, datasetId: string, resourceId?: string) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The parameters for the listDatasets method.
|
|
49
|
+
* - search capability : take param q
|
|
50
|
+
* - pagination capability : take params page and size
|
|
51
|
+
*/
|
|
52
|
+
type ListDatasetsParams<TCapabilities extends Capability[]> = (Includes<TCapabilities, 'search'> extends true ? SearchParams : {}) & (Includes<TCapabilities, 'pagination'> extends true ? PaginationParams : {}) & (Includes<TCapabilities, 'additionalFilters'> extends true ? Record<string, string> : {});
|
|
53
|
+
type SearchParams = {
|
|
54
|
+
q?: string;
|
|
55
|
+
};
|
|
56
|
+
type PaginationParams = {
|
|
57
|
+
page?: number;
|
|
58
|
+
size?: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The metadata of the catalog plugin.
|
|
62
|
+
* @template TCapabilities - This ensures that the `capabilities` field in the metadata is of the same type as `TCapabilities`.
|
|
63
|
+
*/
|
|
64
|
+
export type CatalogMetadata<TCapabilities extends Capability[]> = Metadata & {
|
|
65
|
+
capabilities: TCapabilities;
|
|
66
|
+
};
|
package/catalog/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
$id: string;
|
|
3
|
+
'x-exports': string[];
|
|
4
|
+
type: string;
|
|
5
|
+
additionalProperties: boolean;
|
|
6
|
+
$defs: {
|
|
7
|
+
capability: {
|
|
8
|
+
type: string;
|
|
9
|
+
description: string;
|
|
10
|
+
enum: string[];
|
|
11
|
+
};
|
|
12
|
+
metadata: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
required: string[];
|
|
16
|
+
additionalProperties: boolean;
|
|
17
|
+
properties: {
|
|
18
|
+
title: {
|
|
19
|
+
description: string;
|
|
20
|
+
type: string;
|
|
21
|
+
};
|
|
22
|
+
description: {
|
|
23
|
+
description: string;
|
|
24
|
+
type: string;
|
|
25
|
+
};
|
|
26
|
+
icon: {
|
|
27
|
+
description: string;
|
|
28
|
+
type: string;
|
|
29
|
+
};
|
|
30
|
+
capabilities: {
|
|
31
|
+
description: string;
|
|
32
|
+
type: string;
|
|
33
|
+
items: {
|
|
34
|
+
$ref: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
catalogDataset: {
|
|
40
|
+
type: string;
|
|
41
|
+
description: string;
|
|
42
|
+
required: string[];
|
|
43
|
+
additionalProperties: boolean;
|
|
44
|
+
properties: {
|
|
45
|
+
id: {
|
|
46
|
+
type: string;
|
|
47
|
+
};
|
|
48
|
+
title: {
|
|
49
|
+
type: string;
|
|
50
|
+
};
|
|
51
|
+
description: {
|
|
52
|
+
type: string;
|
|
53
|
+
};
|
|
54
|
+
keywords: {
|
|
55
|
+
type: string;
|
|
56
|
+
items: {
|
|
57
|
+
type: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
origin: {
|
|
61
|
+
type: string;
|
|
62
|
+
};
|
|
63
|
+
image: {
|
|
64
|
+
type: string;
|
|
65
|
+
};
|
|
66
|
+
license: {
|
|
67
|
+
type: string;
|
|
68
|
+
};
|
|
69
|
+
frequency: {
|
|
70
|
+
type: string;
|
|
71
|
+
};
|
|
72
|
+
private: {
|
|
73
|
+
type: string;
|
|
74
|
+
};
|
|
75
|
+
resources: {
|
|
76
|
+
$ref: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
catalogResourceDataset: {
|
|
81
|
+
type: string;
|
|
82
|
+
description: string;
|
|
83
|
+
required: string[];
|
|
84
|
+
additionalProperties: boolean;
|
|
85
|
+
properties: {
|
|
86
|
+
id: {
|
|
87
|
+
type: string;
|
|
88
|
+
};
|
|
89
|
+
title: {
|
|
90
|
+
type: string;
|
|
91
|
+
};
|
|
92
|
+
format: {
|
|
93
|
+
type: string;
|
|
94
|
+
};
|
|
95
|
+
url: {
|
|
96
|
+
type: string;
|
|
97
|
+
};
|
|
98
|
+
fileName: {
|
|
99
|
+
type: string;
|
|
100
|
+
};
|
|
101
|
+
mimeType: {
|
|
102
|
+
type: string;
|
|
103
|
+
};
|
|
104
|
+
size: {
|
|
105
|
+
type: string;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
publication: {
|
|
110
|
+
type: string;
|
|
111
|
+
required: string[];
|
|
112
|
+
additionalProperties: boolean;
|
|
113
|
+
properties: {
|
|
114
|
+
publicationId: {
|
|
115
|
+
type: string;
|
|
116
|
+
description: string;
|
|
117
|
+
};
|
|
118
|
+
catalogId: {
|
|
119
|
+
type: string;
|
|
120
|
+
description: string;
|
|
121
|
+
};
|
|
122
|
+
remoteDatasetId: {
|
|
123
|
+
type: string;
|
|
124
|
+
description: string;
|
|
125
|
+
};
|
|
126
|
+
remoteResourceId: {
|
|
127
|
+
type: string;
|
|
128
|
+
description: string;
|
|
129
|
+
};
|
|
130
|
+
isResource: {
|
|
131
|
+
type: string;
|
|
132
|
+
description: string;
|
|
133
|
+
};
|
|
134
|
+
status: {
|
|
135
|
+
type: string;
|
|
136
|
+
description: string;
|
|
137
|
+
enum: string[];
|
|
138
|
+
};
|
|
139
|
+
publishedAt: {
|
|
140
|
+
type: string;
|
|
141
|
+
description: string;
|
|
142
|
+
format: string;
|
|
143
|
+
};
|
|
144
|
+
error: {
|
|
145
|
+
type: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
export default _default;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
$id: 'https://github.com/data-fair/lib/catalog',
|
|
3
|
+
'x-exports': ['types'],
|
|
4
|
+
type: 'object',
|
|
5
|
+
additionalProperties: false,
|
|
6
|
+
$defs: {
|
|
7
|
+
capability: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
description: `The list of capabilities that a catalog can have.
|
|
10
|
+
- listDatasets: The catalog can list datasets and get one dataset
|
|
11
|
+
- search: The catalog can use a search param in the listDatasets method
|
|
12
|
+
- pagination: The catalog can paginate the results of the listDatasets method
|
|
13
|
+
- publishDataset: The catalog can publish and delete datasets`,
|
|
14
|
+
enum: [
|
|
15
|
+
'listDatasets',
|
|
16
|
+
'publishDataset',
|
|
17
|
+
'search',
|
|
18
|
+
'pagination',
|
|
19
|
+
'additionalFilters'
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
metadata: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
description: 'The metadata of the catalog plugin',
|
|
25
|
+
required: ['title', 'description', 'icon', 'capabilities'],
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
properties: {
|
|
28
|
+
title: {
|
|
29
|
+
description: 'The title of the plugin to be displayed in the UI',
|
|
30
|
+
type: 'string'
|
|
31
|
+
},
|
|
32
|
+
description: {
|
|
33
|
+
description: 'The description of the plugin to be displayed in the UI',
|
|
34
|
+
type: 'string'
|
|
35
|
+
},
|
|
36
|
+
icon: {
|
|
37
|
+
description: 'The SVG Path icon of the plugin',
|
|
38
|
+
type: 'string'
|
|
39
|
+
},
|
|
40
|
+
capabilities: {
|
|
41
|
+
description: 'The list of capabilities that a catalog can have.',
|
|
42
|
+
type: 'array',
|
|
43
|
+
items: {
|
|
44
|
+
$ref: '#/$defs/capability'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
catalogDataset: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
description: 'The normalized dataset format',
|
|
52
|
+
required: ['id', 'title'],
|
|
53
|
+
additionalProperties: false,
|
|
54
|
+
properties: {
|
|
55
|
+
id: {
|
|
56
|
+
type: 'string'
|
|
57
|
+
},
|
|
58
|
+
title: {
|
|
59
|
+
type: 'string'
|
|
60
|
+
},
|
|
61
|
+
description: {
|
|
62
|
+
type: 'string'
|
|
63
|
+
},
|
|
64
|
+
keywords: {
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: {
|
|
67
|
+
type: 'string'
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
origin: {
|
|
71
|
+
type: 'string'
|
|
72
|
+
},
|
|
73
|
+
image: {
|
|
74
|
+
type: 'string'
|
|
75
|
+
},
|
|
76
|
+
license: {
|
|
77
|
+
type: 'string'
|
|
78
|
+
},
|
|
79
|
+
frequency: {
|
|
80
|
+
type: 'string'
|
|
81
|
+
},
|
|
82
|
+
private: {
|
|
83
|
+
type: 'boolean'
|
|
84
|
+
},
|
|
85
|
+
resources: {
|
|
86
|
+
$ref: '#/$defs/catalogResourceDataset'
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
catalogResourceDataset: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
description: 'The normalized resource format',
|
|
93
|
+
required: ['id', 'title', 'format', 'url'],
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
properties: {
|
|
96
|
+
id: {
|
|
97
|
+
type: 'string'
|
|
98
|
+
},
|
|
99
|
+
title: {
|
|
100
|
+
type: 'string'
|
|
101
|
+
},
|
|
102
|
+
format: {
|
|
103
|
+
type: 'string'
|
|
104
|
+
},
|
|
105
|
+
url: {
|
|
106
|
+
type: 'string'
|
|
107
|
+
},
|
|
108
|
+
fileName: {
|
|
109
|
+
type: 'string'
|
|
110
|
+
},
|
|
111
|
+
mimeType: {
|
|
112
|
+
type: 'string'
|
|
113
|
+
},
|
|
114
|
+
size: {
|
|
115
|
+
type: 'number'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
publication: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
required: ['catalogId', 'status'],
|
|
122
|
+
additionalProperties: false,
|
|
123
|
+
properties: {
|
|
124
|
+
publicationId: {
|
|
125
|
+
type: 'string',
|
|
126
|
+
description: 'Id of this publication, for a better search in database'
|
|
127
|
+
},
|
|
128
|
+
catalogId: {
|
|
129
|
+
type: 'string',
|
|
130
|
+
description: 'Id of the catalog where the resource is published'
|
|
131
|
+
},
|
|
132
|
+
remoteDatasetId: {
|
|
133
|
+
type: 'string',
|
|
134
|
+
description: 'Id of the dataset in the remote catalog'
|
|
135
|
+
},
|
|
136
|
+
remoteResourceId: {
|
|
137
|
+
type: 'string',
|
|
138
|
+
description: 'Id of the resource in the dataset in the remote catalog, used if a DataFair dataset is published as a resource in a remote catalog'
|
|
139
|
+
},
|
|
140
|
+
isResource: {
|
|
141
|
+
type: 'boolean',
|
|
142
|
+
description: 'True if the publication is a resource, false or undefined if it is a dataset '
|
|
143
|
+
},
|
|
144
|
+
status: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
description: 'A simple flag to clearly identify the publications that were successful. If "error" then the error key should be defined.',
|
|
147
|
+
enum: ['waiting', 'published', 'error', 'deleted']
|
|
148
|
+
},
|
|
149
|
+
publishedAt: {
|
|
150
|
+
type: 'string',
|
|
151
|
+
description: 'Date of the last update for this publication',
|
|
152
|
+
format: 'date-time'
|
|
153
|
+
},
|
|
154
|
+
error: {
|
|
155
|
+
type: 'string'
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|