@data-fair/lib-common-types 1.10.6 → 1.11.0
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 +3 -7
- package/catalog/index.d.ts +139 -6
- package/catalog/schema.d.ts +0 -4
- package/catalog/schema.js +3 -7
- package/package.json +1 -1
package/catalog/.type/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export const schemaExports: string[]
|
|
|
5
5
|
/**
|
|
6
6
|
* The list of capabilities that a catalog can have.
|
|
7
7
|
* - import: The plugin can list some resources organized in folders and import them
|
|
8
|
-
* - search: The plugin can use
|
|
9
|
-
* - pagination: The plugin can paginate the results of the
|
|
10
|
-
* - additionalFilters: The plugin can use additional filters in the
|
|
8
|
+
* - search: The plugin can use the search param 'q' in the list method
|
|
9
|
+
* - pagination: The plugin can paginate the results of the list method
|
|
10
|
+
* - additionalFilters: The plugin can use additional filters in the list method
|
|
11
11
|
* - importConfig: The plugin gives an import configuration schema
|
|
12
12
|
* - publishDataset: The plugin can publish a dataset
|
|
13
13
|
* - deletePublication: The plugin can delete a dataset or a resource published in a remote catalog
|
|
@@ -86,10 +86,6 @@ export type Resource = {
|
|
|
86
86
|
* via the `definition` "publication".
|
|
87
87
|
*/
|
|
88
88
|
export type Publication = {
|
|
89
|
-
/**
|
|
90
|
-
* The URL of the publication site where the user will be redirected from the remote catalog
|
|
91
|
-
*/
|
|
92
|
-
publicationSite?: string;
|
|
93
89
|
/**
|
|
94
90
|
* Dataset from the remote catalog, used if a local dataset is published as a dataset on a remote catalog. If it is defined during publication, then the remote dataset must be updated.
|
|
95
91
|
*/
|
package/catalog/index.d.ts
CHANGED
|
@@ -13,6 +13,29 @@ type BaseCatalogPlugin<TCatalogConfig, TCapabilities extends Capability[]> = {
|
|
|
13
13
|
configSchema: TCatalogConfig;
|
|
14
14
|
/** Function to validates the catalog configuration. */
|
|
15
15
|
assertConfigValid(catalogConfig: any): asserts catalogConfig is TCatalogConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Prepare function to extract secrets to cipher from the configuration,
|
|
18
|
+
* and dynamically update capabilities.
|
|
19
|
+
* This function is called when the catalog configuration is updated.
|
|
20
|
+
* It can be used to:
|
|
21
|
+
* - throw additional errors to validate the config
|
|
22
|
+
* - remove secrets from the config and store them in the secrets object :<br>
|
|
23
|
+
* This function must copy the configuration fields to be encrypted into the secret object,
|
|
24
|
+
* then replace these fields in the configuration with ****.
|
|
25
|
+
* If the received configuration already contains ****, the secret should not be copied.
|
|
26
|
+
* If the field is empty, it should delete the secret.
|
|
27
|
+
* - update the capabilities of the catalog based on the configuration
|
|
28
|
+
*
|
|
29
|
+
* @param context.catalogConfig The catalog configuration, that can contain secrets to extract
|
|
30
|
+
* @param context.capabilities The actuals capabilities of the catalog
|
|
31
|
+
* @param context.secrets The actuals deciphered secrets of the catalog
|
|
32
|
+
* @returns A promise that resolves to an object containing the catalog configuration, capabilities, and secrets.
|
|
33
|
+
*/
|
|
34
|
+
prepare: (context: PrepareContext<TCatalogConfig, TCapabilities>) => Promise<{
|
|
35
|
+
catalogConfig?: TCatalogConfig;
|
|
36
|
+
capabilities?: TCapabilities;
|
|
37
|
+
secrets?: Record<string, string>;
|
|
38
|
+
}>;
|
|
16
39
|
};
|
|
17
40
|
/**
|
|
18
41
|
* Type for catalog implementations that support listing and retrieving resources.
|
|
@@ -24,19 +47,22 @@ type BaseCatalogPlugin<TCatalogConfig, TCapabilities extends Capability[]> = {
|
|
|
24
47
|
type WithImport<TCatalogConfig, TCapabilities extends Capability[]> = {
|
|
25
48
|
/** List available folders and resources in the catalog. */
|
|
26
49
|
list: (context: ListContext<TCatalogConfig, TCapabilities>) => Promise<{
|
|
50
|
+
/** The total number of items in the current folder */
|
|
27
51
|
count: number;
|
|
52
|
+
/** The list of folders and resources in the current folder, filtered with the search and pagination parameters */
|
|
28
53
|
results: (Folder | Resource)[];
|
|
54
|
+
/** The path to the current folder, including the current folder itself, used to navigate back */
|
|
29
55
|
path: Folder[];
|
|
30
56
|
}>;
|
|
31
57
|
/** Get informations about a specific resource. */
|
|
32
|
-
getResource: (
|
|
58
|
+
getResource: (context: GetResourceContext<TCatalogConfig>) => Promise<Resource | undefined>;
|
|
33
59
|
/**
|
|
34
60
|
* Download the resource to a temporary file from a context
|
|
35
61
|
* @returns The path to the downloaded resource file, or undefined if the download failed
|
|
36
62
|
*/
|
|
37
63
|
downloadResource: (context: DownloadResourceContext<TCatalogConfig>) => Promise<string | undefined>;
|
|
38
64
|
} & (Includes<TCapabilities, 'additionalFilters'> extends true ? {
|
|
39
|
-
|
|
65
|
+
listFiltersSchema: Record<string, any>;
|
|
40
66
|
} : {}) & (Includes<TCapabilities, 'importConfig'> extends true ? {
|
|
41
67
|
importConfigSchema: Record<string, any>;
|
|
42
68
|
} : {});
|
|
@@ -46,9 +72,10 @@ type WithPublishDataset<TCatalogConfig> = {
|
|
|
46
72
|
* @param catalogConfig The configuration of the catalog
|
|
47
73
|
* @param dataset The datafair dataset to publish
|
|
48
74
|
* @param publication The publication to process
|
|
75
|
+
* @param publicationSite The site where the user will be redirected from the remote dataset
|
|
49
76
|
* @returns A promise that is resolved when the dataset is published
|
|
50
77
|
*/
|
|
51
|
-
publishDataset: (
|
|
78
|
+
publishDataset: (context: PublishDatasetContext<TCatalogConfig>) => Promise<Publication>;
|
|
52
79
|
};
|
|
53
80
|
type WithDeletePublication<TCatalogConfig> = {
|
|
54
81
|
/**
|
|
@@ -57,39 +84,145 @@ type WithDeletePublication<TCatalogConfig> = {
|
|
|
57
84
|
* @param datasetId The id of the remoteDataset to delete, or the dataset where the resource to delete is
|
|
58
85
|
* @param resourceId The id of the resource to delete
|
|
59
86
|
*/
|
|
60
|
-
deleteDataset: (
|
|
87
|
+
deleteDataset: (context: DeletePublicationContext<TCatalogConfig>) => Promise<void>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Context for preparing a catalog configuration.
|
|
91
|
+
* @template TCatalogConfig - The type of the catalog configuration.
|
|
92
|
+
* @template TCapabilities - The capabilities of the catalog.
|
|
93
|
+
* @property catalogConfig - The catalog configuration, that can contain secrets to extract.
|
|
94
|
+
* @property capabilities - The actuals capabilities of the catalog.
|
|
95
|
+
* @property secrets - The actuals deciphered secrets of the catalog, if any.
|
|
96
|
+
*/
|
|
97
|
+
export type PrepareContext<TCatalogConfig, TCapabilities extends Capability[]> = {
|
|
98
|
+
/** The catalog configuration, that can contain secrets to extract */
|
|
99
|
+
catalogConfig: TCatalogConfig;
|
|
100
|
+
/** The actuals capabilities of the catalog */
|
|
101
|
+
capabilities: TCapabilities;
|
|
102
|
+
/** The actuals deciphered secrets of the catalog */
|
|
103
|
+
secrets: Record<string, string>;
|
|
61
104
|
};
|
|
62
105
|
export type ListContext<TCatalogConfig, TCapabilities extends Capability[]> = {
|
|
63
106
|
/** The catalog configuration */
|
|
64
107
|
catalogConfig: TCatalogConfig;
|
|
108
|
+
/** The deciphered secrets of the catalog */
|
|
109
|
+
secrets: Record<string, string>;
|
|
65
110
|
/** The specific import configuration, if applicable */
|
|
66
111
|
params: ListParams<TCapabilities>;
|
|
67
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* Parameters for listing resources in a catalog.
|
|
115
|
+
* @template TCapabilities - The capabilities of the catalog.
|
|
116
|
+
* @property currentFolderId - The ID of the current folder used to list subfolders and resources.
|
|
117
|
+
* @property q - The search field to filter resources when the 'search' capability is included.
|
|
118
|
+
* @property page - The page number for pagination when the 'pagination' capability is included.
|
|
119
|
+
* @property size - The number of items per page for pagination when the 'pagination' capability is included.
|
|
120
|
+
* @property others - Additional filters for the list method when the 'additionalFilters' capability is included.
|
|
121
|
+
*/
|
|
68
122
|
type ListParams<TCapabilities extends Capability[]> = {
|
|
69
123
|
/** The current level folder is used to list subfolders and resources. */
|
|
70
124
|
currentFolderId?: string;
|
|
71
|
-
} & (Includes<TCapabilities, 'search'> extends true ? SearchParams : {}) & (Includes<TCapabilities, 'pagination'> extends true ? PaginationParams : {}) & (Includes<TCapabilities, 'additionalFilters'> extends true ? Record<string, string> : {});
|
|
125
|
+
} & (Includes<TCapabilities, 'search'> extends true ? SearchParams : {}) & (Includes<TCapabilities, 'pagination'> extends true ? PaginationParams : {}) & (Includes<TCapabilities, 'additionalFilters'> extends true ? Record<string, string | number> : {});
|
|
126
|
+
/** The params q is used to search resources */
|
|
72
127
|
type SearchParams = {
|
|
73
128
|
q?: string;
|
|
74
129
|
};
|
|
130
|
+
/** The params page and size are used for pagination */
|
|
75
131
|
type PaginationParams = {
|
|
76
132
|
page?: number;
|
|
77
133
|
size?: number;
|
|
78
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* Context for getting a resource.
|
|
137
|
+
* @template TCatalogConfig - The type of the catalog configuration.
|
|
138
|
+
* @property catalogConfig - The catalog configuration.
|
|
139
|
+
* @property secrets - The deciphered secrets of the catalog.
|
|
140
|
+
* @property resourceId - The ID of the remote resource to get.
|
|
141
|
+
*/
|
|
142
|
+
export type GetResourceContext<TCatalogConfig> = {
|
|
143
|
+
/** The catalog configuration */
|
|
144
|
+
catalogConfig: TCatalogConfig;
|
|
145
|
+
/** The deciphered secrets of the catalog */
|
|
146
|
+
secrets: Record<string, string>;
|
|
147
|
+
/** The ID of the remote resource to get */
|
|
148
|
+
resourceId: string;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Context for downloading a resource.
|
|
152
|
+
* @template TCatalogConfig - The type of the catalog configuration.
|
|
153
|
+
* @property catalogConfig - The catalog configuration.
|
|
154
|
+
* @property secrets - The deciphered secrets of the catalog.
|
|
155
|
+
* @property importConfig - The specific import configuration, if applicable.
|
|
156
|
+
* @property resourceId - The ID of the remote resource to download.
|
|
157
|
+
* @property tmpDir - The path to the working directory where the resource will be downloaded.
|
|
158
|
+
*/
|
|
79
159
|
export type DownloadResourceContext<TCatalogConfig> = {
|
|
80
160
|
/** The catalog configuration */
|
|
81
161
|
catalogConfig: TCatalogConfig;
|
|
162
|
+
/** The deciphered secrets of the catalog */
|
|
163
|
+
secrets: Record<string, string>;
|
|
82
164
|
/** The specific import configuration, if applicable */
|
|
83
165
|
importConfig: Record<string, any>;
|
|
84
166
|
/** The ID of the remote resource to download */
|
|
85
167
|
resourceId: string;
|
|
86
|
-
/** The path to the working directory */
|
|
168
|
+
/** The path to the working directory where the resource will be downloaded */
|
|
87
169
|
tmpDir: string;
|
|
88
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Context for publishing a dataset.
|
|
173
|
+
* @template TCatalogConfig - The type of the catalog configuration.
|
|
174
|
+
* @property catalogConfig - The catalog configuration.
|
|
175
|
+
* @property secrets - The deciphered secrets of the catalog.
|
|
176
|
+
* @property dataset - The datafair dataset to publish.
|
|
177
|
+
* @property publication - The publication to process.
|
|
178
|
+
* @property publicationSite - The site where the user will be redirected from the remote dataset.
|
|
179
|
+
* @property publicationSite.title - The title of the publication site.
|
|
180
|
+
* @property publicationSite.url - The URL of the publication site.
|
|
181
|
+
* @property publicationSite.datasetUrlTemplate - The template for the URL to view the dataset in the publication site, using url-template syntax.
|
|
182
|
+
*/
|
|
183
|
+
export type PublishDatasetContext<TCatalogConfig> = {
|
|
184
|
+
/** The catalog configuration */
|
|
185
|
+
catalogConfig: TCatalogConfig;
|
|
186
|
+
/** The deciphered secrets of the catalog */
|
|
187
|
+
secrets: Record<string, string>;
|
|
188
|
+
/** The datafair dataset to publish */
|
|
189
|
+
dataset: Record<string, any>;
|
|
190
|
+
/** The publication to process */
|
|
191
|
+
publication: Publication;
|
|
192
|
+
/** The site where the user will be redirected from the remote dataset. */
|
|
193
|
+
publicationSite: {
|
|
194
|
+
/** The title of the publication site */
|
|
195
|
+
title: string;
|
|
196
|
+
/** The URL of the publication site */
|
|
197
|
+
url: string;
|
|
198
|
+
/** The template for the URL to view the dataset in the publication site, using url-template syntax. */
|
|
199
|
+
datasetUrlTemplate: string;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Context for deleting a publication.
|
|
204
|
+
* @template TCatalogConfig - The type of the catalog configuration.
|
|
205
|
+
* @property catalogConfig - The catalog configuration.
|
|
206
|
+
* @property secrets - The deciphered secrets of the catalog.
|
|
207
|
+
* @property datasetId - The ID of the remote dataset to delete, or the dataset where the resource to delete is.
|
|
208
|
+
* @property resourceId - The ID of the resource to delete, if applicable.
|
|
209
|
+
*/
|
|
210
|
+
export type DeletePublicationContext<TCatalogConfig> = {
|
|
211
|
+
/** The catalog configuration */
|
|
212
|
+
catalogConfig: TCatalogConfig;
|
|
213
|
+
/** The deciphered secrets of the catalog */
|
|
214
|
+
secrets: Record<string, string>;
|
|
215
|
+
/** The ID of the remote dataset to delete, or the dataset where the resource to delete is */
|
|
216
|
+
datasetId: string;
|
|
217
|
+
/** The ID of the resource to delete, if applicable */
|
|
218
|
+
resourceId?: string;
|
|
219
|
+
};
|
|
89
220
|
/**
|
|
90
221
|
* The metadata of the catalog plugin.
|
|
91
222
|
* @template TCapabilities - This ensures that the `capabilities` field in the metadata is of the same type as `TCapabilities`.
|
|
223
|
+
* @property capabilities - The capabilities of the catalog plugin, which is an array of `Capability` types.
|
|
92
224
|
*/
|
|
93
225
|
export type CatalogMetadata<TCapabilities extends Capability[]> = Metadata & {
|
|
226
|
+
/** The capabilities of the catalog plugin */
|
|
94
227
|
capabilities: TCapabilities;
|
|
95
228
|
};
|
package/catalog/schema.d.ts
CHANGED
package/catalog/schema.js
CHANGED
|
@@ -9,9 +9,9 @@ export default {
|
|
|
9
9
|
type: 'string',
|
|
10
10
|
description: `The list of capabilities that a catalog can have.
|
|
11
11
|
- import: The plugin can list some resources organized in folders and import them
|
|
12
|
-
- search: The plugin can use
|
|
13
|
-
- pagination: The plugin can paginate the results of the
|
|
14
|
-
- additionalFilters: The plugin can use additional filters in the
|
|
12
|
+
- search: The plugin can use the search param 'q' in the list method
|
|
13
|
+
- pagination: The plugin can paginate the results of the list method
|
|
14
|
+
- additionalFilters: The plugin can use additional filters in the list method
|
|
15
15
|
- importConfig: The plugin gives an import configuration schema
|
|
16
16
|
- publishDataset: The plugin can publish a dataset
|
|
17
17
|
- deletePublication: The plugin can delete a dataset or a resource published in a remote catalog`,
|
|
@@ -123,10 +123,6 @@ export default {
|
|
|
123
123
|
additionalProperties: false,
|
|
124
124
|
description: 'A small object that contains the information needed to publish or update a dataset or a resource',
|
|
125
125
|
properties: {
|
|
126
|
-
publicationSite: {
|
|
127
|
-
type: 'string',
|
|
128
|
-
description: 'The URL of the publication site where the user will be redirected from the remote catalog'
|
|
129
|
-
},
|
|
130
126
|
remoteDataset: {
|
|
131
127
|
type: 'object',
|
|
132
128
|
required: ['id'],
|